【发布时间】:2017-08-11 07:34:54
【问题描述】:
我的 XAML 代码如下所示
<StackPanel Orientation="Vertical">
<Ellipse x:Name="dp" Height="250" Width="250" Margin="0,10,0,0">
<Ellipse.Fill>
<ImageBrush ImageSource="Assets/img.jpg"/>
</Ellipse.Fill>
</Ellipse>
<Button Content="Upload Image" Margin="236,0,0,0" Click="Button_Click"/>
</StackPanel>
&想要通过单击按钮更改背景图像(“上传图像”) & 这是我在 C# 中的后端编码
FileOpenPicker fop = new FileOpenPicker();
fop.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
fop.FileTypeFilter.Add(".jpg");
fop.FileTypeFilter.Add(".jpeg");
StorageFile file = await fop.PickSingleFileAsync();
IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
if (file!=null)
{
BitmapImage bmp = new BitmapImage(new Uri(stream.));
ImageBrush brush = new ImageBrush();
brush.ImageSource = bmp;
}
我是窗口应用程序的初学者
【问题讨论】: