2011-12-16 67 views
0

視圖有一個按鈕和圖像控件。我已經將按鈕命令綁定到ViewModel上的一個delegateCommand,它打開一個文件對話框供用戶選擇一個Image.The上下文「object」 for View包含一個屬性「Icon」,其類型爲byte []。我已經將圖標綁定到Image控件。問題是如何在圖像控件上顯示選定的圖像文件?如何更新按鈕上的圖像點擊命令

的XAML:

<Button x:Name="dlgIconbtn" Command="{Binding OpenFileCommand}" Content="Choose Icon" MaxWidth="120" Grid.Row="3" Grid.Column="1" Margin="5"/> 
     <Image Grid.Row="3" Margin="5" Grid.Column="3" Source="{Binding AppItem.Icon,Converter={StaticResource imgConverter}}" 
       Width="25" Height="25"/> 
+0

標籤不會爲您的標題添加任何內容。 – Will 2011-12-16 17:27:54

回答

0

我假設你的轉換器工作正常。 現在當OpenFileCommand火災用戶選擇圖像,並更新App.Icon財產與新Byte[]。 現在請RaiseProperty在Icon上更改事件,以便Binding得到刷新。

我不認爲你需要任何代碼在這裏。

如果仍不能再工作,請更新您提供齊全的XAML代碼+質詢視圖模型

0

我解決它使用視圖模型屬性「ImgSource」這勢必給ImageControl.Whenever的用戶選擇的源圖像使用按鈕命令我設置圖像文件的內容到「ImgSource」,它的工作原理。