I want to create a Button that changes by a bool and isMouseOver
value.
- player is playing -> Pause_grey.png
- player is playing & mouseIsOver-> Pause_blue.png
- player is stopped -> Play_grey.png
- player is stopped & mouseIsOver -> Play_blue.png
I want to do this with 4 MultiDataTrigger
but when the playStatus
(boolean value of dataContext
) changes the button is not recognizing it
Code:
Button:
<Button Name="btnPlayPause" Grid.Column="2" Grid.Row="0" Click="musikPlayer_btnClick" HorizontalAlignment="Center" Style="{StaticResource PlayPauseButton}"></Button>
Style of Button:
<Style TargetType="{x:Type Button}" x:Key="PlayPauseButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<StackPanel Orientation="Horizontal" >
<Image Name="PART_Image" Source="graphics/Pause_grey.png" VerticalAlignment="Center" RenderOptions.BitmapScalingMode="HighQuality" ></Image>
</StackPanel>
<ControlTemplate.Triggers>
<MultiDataTrigger >
<MultiDataTrigger.Conditions>
<!--is not playing and mouse is not over-->
<Condition Binding="{Binding playStatus}" Value="false"/>
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="false" />
</MultiDataTrigger.Conditions>
<Setter Property="Source" Value="graphics/Play_grey.png" TargetName="PART_Image"/>
</MultiDataTrigger>
<MultiDataTrigger >
<MultiDataTrigger.Conditions>
<!--is not playing and mous is over-->
<Condition Binding="{Binding playStatus}" Value="false"/>
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="Source" Value="graphics/Play_blue.png" TargetName="PART_Image"/>
</MultiDataTrigger>
<MultiDataTrigger >
<MultiDataTrigger.Conditions>
<!--is playing and mous is not over-->
<Condition Binding="{Binding playStatus}" Value="true"/>
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="false" />
</MultiDataTrigger.Conditions>
<Setter Property="Source" Value="graphics/Pause_grey.png" TargetName="PART_Image"/>
</MultiDataTrigger>
<MultiDataTrigger >
<MultiDataTrigger.Conditions>
<!--is playing and mouse is over-->
<Condition Binding="{Binding playStatusy}" Value="true"/>
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="Source" Value="graphics/Pause_blue.png" TargetName="PART_Image"/>
</MultiDataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
So anyone know how to get this working? :)
EDIT1:
I don't know how, or if I can setup INotifyPropertyChanged
because of the value:
public Boolean playStatus { get { return !model.getMusicPlayer().getStream1_pause(); } }
EDIT2: I tried this but it doesnt work
protected void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, e);
}
protected void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
public bool stream1_pause
{
get { return Stream1_pause; }
set
{
if (value != Stream1_pause)
{
Stream1_pause = value;
OnPropertyChanged("stream1_pause");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
Maybe I should call update manually like I can do in listView, but I don't know how to update the conditions. In ListView it looks like:
BindingOperations.GetBindingExpressionBase(songs, ListView.ItemsSourceProperty).UpdateTarget();
So I tried:
BindingOperations.GetBindingExpressionBase(btnPlayPause, Button.StyleProperty).UpdateTarget();
but it says:
System.NullReferenceException
.... the question is why?