<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:myapp="clr-namespace:MyPlayer.Model"
mc:Ignorable="d"
x:Class="MyPlayer.VolumeButtons"
x:Name="UserControl"
d:DesignWidth="640" d:DesignHeight="480">
<UserControl.Resources>
<myapp:MusicPlayerModel x:Key="Model"/>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" DataContext="{StaticResource Model}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="35px"/>
<ColumnDefinition Width="1.0*"/>
</Grid.ColumnDefinitions>
<Slider Value="{Binding Volume}" Margin="0,0,0,0" Grid.Column="1" VerticalAlignment="Center" x:Name="volumeSlider"/>
<Button Margin="4,4,4,4" Content="Button" x:Name="muteButton" Click="MuteButton_Click"/>
</Grid>
</UserControl>
Now the thing is, databinding is working correct when I am moving my slider(the model is updated when I am moving the slider).
However when a button is clicked I change the value in the model and expects it to update the view.
Code below:
private void MuteButton_Click(object sender, RoutedEventArgs e)
{
musicPlayerModel.Volume = 0;
}
Code in model:
public double Volume
{
get { return this.volume; }
set
{
this.volume = value;
this.OnPropertyChanged("SomeTestText");
this.OnPropertyChanged("Volume");
}
}
But in OnPropertyChanged, the event is null and therefor nothing happens. Why is the event null and not when my slider is moving and how to solve it?