2016-04-17 2 views
0

アプリケーションパッケージ外のImageSourceを変更するにはどうすればよいですか?私はこれを使用しています:ImageSourceをアプリケーションパッケージ外のパスに設定する

FileOpenPicker picker = new FileOpenPicker(); 
picker.FileTypeFilter.Add(".jpg"); 
StorageFile file = await picker.PickSingleFileAsync(); 

if (file != null) 
{ 
    grid.Background = new ImageBrush 
    { 
     ImageSource = new BitmapImage(new Uri(file.Path, UriKind.Absolute)) 
    }; 
} 

しかし、私が望む画像を選んだ後、それはグリッドの背景として表示されません。それは何も表示されません!ここにXAMLがあります。

<Border BorderBrush="Black" BorderThickness="1" Margin="315,260,85,140" Width="100" Height="100"> 
    <Grid x:Name="grid" Margin="0" Visibility="Visible"> 
    </Grid> 
</Border> 

ありがとうございます!

答えて

0

あなたは最初のファイルを開くことがあります:あなたの助けのための

if (file != null) 
{ 
    var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); 

    var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); 
    await bitmapImage.SetSourceAsync(stream); 

    var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream); 

    grid.Background = new ImageBrush 
    { 

     ImageSource = bitmapImage 
    }; 
} 
+0

おかげであなたを! –