Hello Karl,
I just created a simple textbox custom control without any attributes.If this is solved then i thought of giving attributes.
So this is my code
I have added ClassLibrary in WPF application.In ClassLibrary
under Generic.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CustControlLibrary.WpfAppCustCtrl">
<Style TargetType="{x:Type local:CTextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CTextBox}">
<TextBox Width="300" Height="150">
</TextBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Under CTextBox.vb
Public Class CTextBox
Inherits System.Windows.Controls.TextBox
Shared Sub New()
'This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
'This style is defined in Themes\Generic.xaml
DefaultStyleKeyProperty.OverrideMetadata(GetType(CTextBox), New FrameworkPropertyMetadata(GetType(CTextBox)))
End Sub
After adding References of classlibrary i just tried to use my custom control inmy application then i got anerror as cannot create an instance ofType "CTextBox"
Under Window.xaml
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Employee Details" Height="300" Width="600"
xmlns:cc="clr-namespace:CustControlLibrary.WpfAppCustCtrl;assembly=CustControlLibrary">
<Window.Resources>
<XmlDataProvider x:Key="CustomerListData" Source="Details.xml"
XPath="/CustomerList/Customer"></XmlDataProvider>
</Window.Resources>
<Grid>
<cc:CTextBox></cc:CTextBox>(Error is raised here)
</Grid>
</Window>
Thanks in Advance