我想改變我的按鈕的背景圖像其他一些圖像,我遇到了一些錯誤。 這是我對我的XAML代碼:如何在C#WPF代碼中更改設置按鈕的背景圖像?
<Button x:Name="Button1" Width="200" Height="200" Content="Button1" Margin="0,0,0,400">
<Button.Background>
<ImageBrush **ImageSource ="Images/AERO.png"** ></ImageBrush>
</Button.Background>
</Button>
和我的CS:
private void Button1_Click_1(object sender, RoutedEventArgs e)
{
var brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri("Images/AERO.png"));
Button1.Background = brush;
}
我有我的XAML中的錯誤是「文件‘圖片\ logo.png’不是一部分 任何人都可以幫我解釋一下,謝謝
你能否證實在Visual Studio項目文件「圖像\ logo.png」是否被incuded。如果是,您是否也可以在其屬性選項卡上確認其生成操作已設置爲資源? – Kohanz 2013-04-09 02:36:10
我該如何設置Build Action屬性?我似乎無法找到它。該文件 – Jaz 2013-04-09 02:41:43
單擊鼠標右鍵,選擇屬性 – Kohanz 2013-04-09 02:43:17