I try set a guid or text (string) on my own control on xaml, but not work.
Code:
public class MyLabel : Label
{
[Category("Guid")]
public static DependencyProperty MyControlGuidProperty =
DependencyProperty.Register("MyControlGuid", typeof(Guid), typeof(MyLabel));
[Category("Guid")]
public Guid MyControlGuid
{
get
{
return (Guid)GetValue(MyControlGuidProperty);
}
set
{
SetValue(MyControlGuidProperty, value);
}
}
public MyLabel()
: base()
{
SetValue(MyControlGuidProperty, Guid.NewGuid());
}
}
But doesn't works. When i drag the new control form toolbox to MainWindows.xaml - generated the MyLabel but not MyControlGuid on Xaml. Under properties have the MyLabel a valied guid.
Only when i click at box at the end of the MyControlGuid - i can choose "convert to local value" and the guid was set it on xaml.
I get only
<local:MyLabel Content="MyLabel" HorizontalAlignment="Left" Margin="193,79,0,0" VerticalAlignment="Top"/>
but i want
<local:MyLabel Content="MyLabel" HorizontalAlignment="Left" Margin="193,79,0,0" VerticalAlignment="Top" MyControlGuid="6c090537-4a06-41d5-a0ea-6d3112df0f77"/>
this i get only over WPF Property Grid and click convert to local value.
What i must to do for that in code on my control (convert to local value)?
What I have tried:
I have try with the Attribute
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
but not works.
I have try PropertyChangedCallback and CoerceValueCallback - not works too.