User Control - dependency property to Change Image Issues
- by mflair2000
i'm having issues setting the Image from a dependency property. It seems like the trigger doesnt fire. I just want hide/show and image, or set the source if possible.
public static readonly DependencyProperty HasSingleValueProperty =
DependencyProperty.Register("HasSingleValue", typeof(bool), typeof(LevelControl), new
FrameworkPropertyMetadata(false,FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public bool HasSingleValue
{
get { return (bool)GetValue(HasSingleValueProperty); }
set { SetValue(HasSingleValueProperty, value); }
}
public LevelControl()
{
this.InitializeComponent();
//this.DataContext = this;
LayoutRoot.DataContext = this;
}
//Control Markup
<Grid x:Name="LayoutRoot">
<Image x:Name="xGreenBarClientTX" HorizontalAlignment="Stretch" Height="13" Margin="7,8.5,7,0"
Stretch="Fill"
VerticalAlignment="Top"
Width="47"
Canvas.Left="181.67"
d:LayoutOverrides="Height" >
<Image.Style>
<Style TargetType="{x:Type Image}">
<Style.Triggers>
<DataTrigger Binding="{Binding HasSingleValue}" Value="True">
<Setter Property="Opacity" Value="100"/>
</DataTrigger>
<DataTrigger Binding="{Binding HasSingleValue}" Value="False">
<Setter Property="Opacity" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>