I am strugling to bind value to path ImageSource. I get NullReferenceError when I try to set new value. My current code is:
In MainWindow.xaml the Path code is following
In code behind you have to use complete Pack URIs, including the pack://application:,,,
prefix. And you should not specify UriKind.Relative
.
private void Path_MouseEnter_1(object sender, MouseEventArgs e)
{
image.ImageSource = new Uri("pack://application:,,,/RoundUI;component/sadface.png");
}
Edit: It seems that you are confusing a few things here. For now it might perhaps be easier not to bind the ImageBrush's ImageSource
property, but instead set it directly in code behind, as shown in this answer to your previous question:
<Path x:Name="PPButton" ...
MouseEnter="Path_MouseEnter_1" MouseLeave="Path_MouseLeave_1" >
<Path.Fill>
<ImageBrush/>
</Path.Fill>
</Path>
Code behind:
private void Path_MouseEnter_1(object sender, MouseEventArgs e)
{
var imageBrush = PPButton.Fill as ImageBrush;
image.ImageSource = new Uri("pack://application:,,,/RoundUI;component/sadface.png");
}