User Control - dependency property to Change Image Issues

Posted by mflair2000 on Stack Overflow See other posts from Stack Overflow or by mflair2000
Published on 2012-11-13T21:49:28Z Indexed on 2012/11/13 23:00 UTC
Read the original article Hit count: 211

Filed under:
|

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>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about usercontrols