0

i'm trying to style my image according to dependancy object i defined as followed:

in MainWindow.xaml:

<ObjectDataProvider x:Key="GetIsConnected"
                ObjectType="{x:Type ConnectionRepository:ConnectionRepository}" />

    <Image Name="ConnectStatusBarImage" Width="16" Height="16">
        <Image.Style>
            <Style>
                <Setter Property="Image.Source" Value="/Images/connected16.png" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Source={StaticResource GetIsConnected}, Path=IsConnected}" Value="true">
                        <Setter Property="Image.Source" Value="/Images/disconnected16.png" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Image.Style>
    </Image>

the repository code looks like that:

public class ConnectionRepository : DependencyObject  
    {
    public bool IsConnected
    {
        get { return (bool)GetValue(IsConnectedProperty); }
        set { SetValue(IsConnectedProperty, value); }
    }
}


public static readonly DependencyProperty IsConnectedProperty =
    DependencyProperty.Register("IsConnected", 
    typeof(bool), typeof(ConnectionRepository));

i set the IsConnect to true if the connection succeeded.

but for some reason the image is not changing according to this object... and idea what is wrong ?

H.B.
  • 166,899
  • 29
  • 327
  • 400
kaycee
  • 1,199
  • 4
  • 24
  • 42

1 Answers1

0

Despite the fact that you are showing connected16.png when the object is not connected, and switching to disconnected16.png when it is connected, you would have to set IsConnected on the object managed by the ObjectDataProvider:

ObjectDataProvider p = (ObjectDataProvider)Resources["GetIsConnected"];
((ConnectionRepository)p.Data).IsConnected = true;
Clemens
  • 123,504
  • 12
  • 155
  • 268