Setting a "dependency property" in code
Posted
by Matt B
on Stack Overflow
See other posts from Stack Overflow
or by Matt B
Published on 2010-03-29T15:04:43Z
Indexed on
2010/03/30
13:03 UTC
Read the original article
Hit count: 361
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; })); } }
© Stack Overflow or respective owner