mvvm パターンを使用して wpf でアプリケーションを開発しています。
私のアプリケーションでは、画像を選択してフォームに表示し、データベースに保存する必要があります。
wpf フォームでは、イメージ コントロールを使用してイメージを表示しています。
ビュー モデルで、ファイル ダイアログを開き、Image プロパティを割り当てます。
BitmapImage image;
public BitmapImage Image
{
get { return image; }
set
{
image = value;
RaisePropertyChanged("Image");
}
}
...
OpenFileDialog file = new OpenFileDialog();
Nullable<bool> result =file.ShowDialog();
if (File.Exists(file.FileName))
{
image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri(file.FileName, UriKind.Absolute);
image.EndInit();
}
私のxaml部分は
<Image Height="144" HorizontalAlignment="Left" Source="{Binding Image}"
Margin="118,144,0,0" Name="imgData" Stretch="Fill" VerticalAlignment="Top" Width="340" />
フォームに画像が表示されません。どのように?