2014-09-25 75 views
0

我試圖從按鈕中獲取背景圖像以基於MVVM鏈接對象中的值進行更改。更改基於綁定的按鈕背景圖像

該按鈕的默認樣式圖像1,

當物體已被處理成功,該屬性設置爲「成功」和按鈕圖像應更改爲鏡像2

然而當對象不是招沒有被處理成功,該屬性設置爲「錯誤:」,並且按鈕圖像應該變成image3

我已經嘗試綁定到表示文件位置的字符串(直接在ImageBrush上輸入相同的字符串屬性ImageSource在Button.Background標記中。

也返回一個開放的,以該文件不工作

試圖利用與觸發器二傳手標籤,使用

的XAML休息時,並試圖從它創建的BitmapImage與內的額外屬性對象也不起作用。

這是應用程序中剩下的唯一東西。有人有一些建議

+0

你能展示一些代碼嗎? – Romasz 2014-09-25 09:16:33

回答

0

我現在發現了一個可行的解決方案。通過從該按鈕的背景,並加入以下內容:

 <Button.Content> 
     <StackPanel Orientation="Vertical"> 
      <Image Source="{Binding Path=Background}" Stretch="Fill" Height="100" Width="400" /> 
      <TextBlock Margin="0,-130,0,0" Height="30" Width="400" HorizontalAlignment="Center" 
       TextAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=Title}" 
       Foreground="White" FontFamily="/Assets/futura-md.ttf#Futura Md BT"/> 
     </StackPanel> 
     </Button.Content> 

具有背景定義如下:

public BitmapImage Background 
    { 
     get 
     { 
      return new BitmapImage(new Uri(string.Format("/Assets/knop_{0}.png",buttoncolor), UriKind.Relative)); 
     } 
    } 

    public string ButtonImage 
    { 
     get { return buttonimage; } 
     set 
     { 
      buttonimage = value; 
      RaisePropertyChanged("ButtonImage"); 
      RaisePropertyChanged("Background"); 
     } 
    } 

現在按鈕「背景」將被改變時的值ButtonImage已更改。

這不完全是我所希望的,但它的工作。