I have a control where I want to bind a colour to plain property in its own class.
But it fails to work ??? any Clues ?
I have this
public Brush SeperatorColour
{
get { return (Brush)GetValue(SeperatorColourProperty); }
set { SetValue(SeperatorColourProperty, value); }
}
// Using a DependencyProperty as the backing store for SeperatorColour. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SeperatorColourProperty =
DependencyProperty.Register("SeperatorColour", typeof(Brush), typeof(TycoMessageBarMessage), new UIPropertyMetadata(Brushes.Crimson));
And this
<StackPanel Orientation="Horizontal" Background="Black" >
<Rectangle Name="MessageSeperator" Height="auto" Width="10" Fill="{Binding Path=SeperatorColour, ElementName=container, Mode=OneTime}" />
<TextBlock Name="MessageText" Text="Hello" Foreground="White" Margin="5,0" />
</StackPanel>
implies that you are binding to another XAML element named ‘container’, you will probably want to bind to some instance of the object with the ‘SeperatorColour’ property.
If you’re not binding to another XAML element, do not add “ElementName” to the binding expression.