I have this xaml:
<Window x:Class="TestWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" SizeToContent="WidthAndHeight">
<Image Width="100" Height="100" Source="{Binding theImage}"/>
</Window>
And this code behind:
namespace TestWPF
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
BitmapImage theImage = new BitmapImage();
public MainWindow()
{
InitializeComponent();
theImage.BeginInit();
theImage.UriSource = new Uri("dice.png", UriKind.Relative);
theImage.CacheOption = BitmapCacheOption.OnLoad;
theImage.EndInit();
OnPropertyChanged("theImage");
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Why is the image not showing up? I understand my code may be completely backwards. I'm just having trouble wrapping my head around the WPF way. Where things like this in Qt are dead simple, I can't seem to find anything relevant for this.