Reputation: 1759
We have made a WPF CustomControl which inherits from the TextBox and added a new DependencyProperty "TableName", so we can set there the name of the DataTable to which the control is bound. The control is generated at runtime and the property TableName p.e. set to "table1". Then we serialize the Panel which contains the controls (like our CustomControl) to a XAML file like in this article from CodeProject, because we want to serialize the bindings too:
XamlWriter-and-Bindings-Serialization
Unfortunately - instead of properties like Width - our new DependencyProperty is not serialized.
Is there a way to force the XamlWriter to serialize the property?
Thanks in advance!
This is the Definition of the property in the CustomControl called "CustomTextBox":
public static readonly DependencyProperty TableNameProperty = DependencyProperty.Register("TableName", typeof(string), typeof(CustomTextBox));
public string TableName { get; set; }
It's style in the Generic.xaml:
<Style TargetType="{x:Type local:CustomTextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
</Style>
Upvotes: 0
Views: 167
Reputation: 21261
You have provided a CLR property but it doesn't do anything. You need to link it to your DependencyProperty:
public string TableName
{
get { return (string)GetValue(TableNameProperty); }
set { SetValue(TableNameProperty, value); }
}
Upvotes: 0