Hello,
I have own dependency property defined. I use it in ResourceDictionary.
public String StyledContent
{
get { return (
String)this.GetValue(StyledContentProperty); }set { this.
SetValue(StyledContentProperty, value); }}
public static readonly
DependencyProperty StyledContentProperty= DependencyProperty.Register("StyledContent", typeof(String), typeof(Button), new PropertyMetadata(string.Empty));
If I use it in one window, it works well. But if I create another window from the first one (it uses that dependency property too), I get an exception
Cannot convert the value in attribute 'Property' to object of type 'System.Windows.DependencyProperty'. The type initializer for 'WPFForm.OwnProperties2' threw an exception. Error at object 'System.Windows.TemplateBindingExtension' in markup file 'WPFForm;component/dictionary21.xaml' Line 130 Position 24.
I've found only one solution: do not set static readonly StyledContentProperty directly, but do it inside static constructor and "wrap" it into try...catch. Is there any way, how to realize, if my dependency property is already registered I have not found some...
Thank you.
RostaB