Source
コード内で画像をにバインドしBitmapImage
ていますが、表示されません。
xaml:
<Window x:Class="bleh.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="600" d:DesignWidth="600">
<Grid x:Name="LayoutRoot">
<Image x:Name="current" HorizontalAlignment="Center" Stretch="None" VerticalAlignment="Center" Source="{Binding Picture}" />
</Grid>
</Window>
と私のcs:
public partial class MainWindow : Window, INotifyPropertyChanged
{
/// <summary>
/// Event implementing INotifyPropertyChanged interface.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
public BitmapImage Picture { get; set; }
public MainWindow()
{
Uri uri = new Uri("Images/xpto.jpg", UriKind.Relative);
this.Picture = new BitmapImage(uri);
InitializeComponent();
//setup();
}
}
不思議なことに、ウィンドウは画像のサイズで開きますが、画像が表示されません。また、xamlで手動で割り当ててみましたが、機能します。
やることcurrent.source="Images/xpto.jpg"
もうまくいきます。