2017-08-11 40 views
0

我的XAML代碼看起來像這樣想通過C#來上傳圖片在橢圓的背景

<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; 
     } 

我Begineer在窗口應用程序

回答

0

迪,你嘗試做T設置的填充他elipse,如果獲得該文件的代碼工作正常,那麼你應該能夠做到這一點

dp.Fill = brush; 

你也有一個錯字

BitmapImage bmp = new BitmapImage(new Uri(stream.)); extra . after stream 
BitmapImage bmp = new BitmapImage(new Uri(stream)); 
+0

是的,它的作品我都只需添加「BMP .SetSource(流);」這條線在上述條件...謝謝你這麼多 –