我在编程中遇到了设置按钮图片的问题。我有一个WPF按钮:
<Button Name="MyBtn" x:FieldModifier="public" HorizontalAlignment="Center" VerticalAlignment="Center" Click="FlashOnOf_Click" Height="256" Width="256" BorderBrush="{x:Null}"/>
尝试在其中设置图像,并使用以下情况:
var brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri("ms-appx://Assets/light_bulb_off.png"));
brush.Stretch = Stretch.Fill;
MyBtn.Background = brush;
一种更多的情况:
MyBtn.Content = new Image
{
Source = new BitmapImage(new Uri("ms-appx://Assets/light_bulb_off.png")),
VerticalAlignment = VerticalAlignment.Center,
Stretch = Stretch.Fill,
Height = 256,
Width = 256
};
同样没有运气。我在哪里犯了错误?