Setting a "dependency property" in code
- by Matt B
I'm on a roll today...
I have the following code delaring a dependency property inside a class called ActionScreen:
#region Dependency Properties & Methods
public string DescriptionHeader
{
get { return (string)GetValue(DescriptionHeaderProperty); }
set { SetValue(DescriptionHeaderProperty, value); }
}
// Using a DependencyProperty as the backing store for DescriptionHeader. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DescriptionHeaderProperty =
DependencyProperty.Register("DescriptionHeader", typeof(string), typeof(ActionScreen), new UIPropertyMetadata("xxx"));
#endregion
I bind to this property in my Xaml as so:
<GridViewColumn DisplayMemberBinding="{Binding Description}" Header="{Binding DescriptionHeader}" Width="350" />
Now I want to be able to set the parameter from my code behind when I recieve an event - but it's not working:
public string DescColText { set { this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { DescriptionHeader = value; })); } }