how to have many wpf custom controls in the same library? -


i have wpf custom control project in want have many custom controls. default, vs2015 cummunity creates theme folder generic.xaml file , .cs file interaction logic.

i want have many user controls, have tried create mycontrol1 folder, inside folder, have created theme folder , add new item, wpf custom control. doesn't create generic.xaml control. copy root folder default generic.xaml , create style, when use control in wpf application, don't see control.

i have seen post: custom control lib multiple controls , generic.xaml don't understand solution.

i have problem, in mycontrol1.generic.xaml y have code:

<resourcedictionary     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:local="clr-namespace:customcontrols.calendario2">       <style targettype="{x:type local:calendariomes2}">         <setter property="template">             <setter.value>                 <controltemplate targettype="{x:type local:calendariomes2}">                     <border background="{templatebinding background}"                             borderbrush="{templatebinding borderbrush}"                             borderthickness="{templatebinding borderthickness}">                          <grid>                             <textbox text="prueba"/>                             <label content="prueba"/>                         </grid>                      </border>                 </controltemplate>             </setter.value>         </setter>     </style> </resourcedictionary> 

but error in line:

<style targettype="{x:type local:calendariomes2}"> 

that not possible create type text local:calendariomes2.

if use code in library 1 custom control , code in generic.xaml file, works.

so, in sumary, know how have library many custom controls.

thanks.

i have found cleanest way involves creating merged dictionary. customcontrol's tend inherit base control, group them listview, textbox, etc.

generic.xaml

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">     <resourcedictionary.mergeddictionaries>         <resourcedictionary source="/yourassembly;component/resourcedictionaries/listview.xaml"/>         <resourcedictionary source="/yourassembly;component/resourcedictionaries/tabcontrol.xaml"/>         <resourcedictionary source="/yourassembly;component/resourcedictionaries/textbox.xaml"/>     </resourcedictionary.mergeddictionaries> </resourcedictionary> 

textbox.xaml

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                     xmlns:local="clr-namespace:yournamespace">   <!-- describes how style validatedtextbox -->     <style x:key="{x:type local:validatedtextbox}" basedon="{staticresource {x:type textbox}}" targettype="{x:type local:validatedtextbox}">         <setter property="validation.errortemplate">             <setter.value>                 <controltemplate>                     <stackpanel orientation="horizontal">                         <border borderbrush="red" borderthickness="1" verticalalignment="top">                             <adornedelementplaceholder x:name="adorner" />                         </border>                         <border x:name="validationerrorscontainer" background="lightcoral" borderbrush="red" borderthickness="1" margin="5, 0, 0, 0" verticalalignment="top">                             <listview background="transparent" borderthickness="0" focusable="false" ishittestvisible="false"                                       itemssource="{binding adornedelement.(validation.errors), elementname=adorner}">                                 <listview.resources>                                     <style targettype="{x:type gridviewcolumnheader}">                                         <setter property="visibility" value="collapsed" />                                     </style>                                 </listview.resources>                                 <listview.itemtemplate>                                     <datatemplate>                                         <textblock text="{binding errorcontent}" />                                     </datatemplate>                                 </listview.itemtemplate>                             </listview>                         </border>                     </stackpanel>                     <controltemplate.triggers>                         <datatrigger binding="{binding adornedelement.isfocused, elementname=adorner}" value="false">                             <setter targetname="validationerrorscontainer" property="visibility" value="collapsed" />                         </datatrigger>                     </controltemplate.triggers>                 </controltemplate>             </setter.value>         </setter>     </style> </resourcedictionary> 

validatedtextbox.cs

namespace yournamespace {     public class validatedtextbox : textbox     {         static validatedtextbox()         {             defaultstylekeyproperty.overridemetadata(typeof(validatedtextbox), new frameworkpropertymetadata(typeof(validatedtextbox)));         }     } } 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -