2014-10-01 48 views
1

我正在開發一個應用程序,它需要從圖庫中選擇背景圖片。對於這個我在Windows phone 8.1實現相同的功能Choose Photo功能(設置背景圖片),如何在windows phone中實現選擇照片功能

我已經試過這樣:

XAML:

<Grid x:Name="LayoutRoot" Background="Transparent"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 

    <Grid Grid.Row="0" Name="contentPanel"> 
     <ScrollViewer Name="scrl" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" Opacity="0.3"> 

     </ScrollViewer> 
     <ScrollViewer Name="scrlView" Height="500" Width="300" BorderBrush="Red" BorderThickness="1" Background="Transparent"> 

     </ScrollViewer> 
     <Image Name="mtpImg" Stretch="Fill" /> 
    </Grid> 
</Grid> 

<phone:PhoneApplicationPage.ApplicationBar> 
    <shell:ApplicationBar Mode="Minimized"> 
     <shell:ApplicationBarIconButton IconUri="Assets\ApplicationIcon.png" Click="gallery_click" Text="gallery"/> 
    </shell:ApplicationBar> 
</phone:PhoneApplicationPage.ApplicationBar> 

C#:

private void gallery_click(object sender, EventArgs e) 
    { 
     PhotoChooserTask chooser = new PhotoChooserTask(); 
     chooser.Completed += gallery_Completed; 
     chooser.Show(); 
    } 

    private void gallery_Completed(object sender, PhotoResult e) 
    { 
     if (e.TaskResult == TaskResult.OK) 
     { 
      Image img = new Image(); 
      BitmapImage tmpBitmap = new BitmapImage(); 
      tmpBitmap.SetSource(e.ChosenPhoto); 
      img.Source = tmpBitmap; 
      scrl.Content = img; 
     } 
    } 

問題:如何設置opacity=1內部顯示的圖像scrlView ScrollViewer?

回答

1

試試這個設置不透明度爲1:

private void gallery_Completed(object sender, PhotoResult e) 
{ 
    if (e.TaskResult == TaskResult.OK) 
    { 
     Image img = new Image(); 
     BitmapImage tmpBitmap = new BitmapImage(); 
     tmpBitmap.SetSource(e.ChosenPhoto); 
     img.Source = tmpBitmap; 
     scrl.Content = img; 
     scrl.Opacity = 1.0; 
    } 
} 

如果您想設置在圖像控制圖像和邊境你可以試試這個:

XAML:

<Grid Grid.Row="0" Name="contentPanel"> 
    <Border BorderBrush="Red" Height="500" Width="300" BorderThickness="1"> 
     <Image Name="mtpImg" Stretch="Fill" Height="500" Width="300"/> 
    </Border> 
</Grid> 

CS:

PhotoChooserTask chooser; 
public TaskPage() 
{ 
    InitializeComponent(); 
    chooser = new PhotoChooserTask(); 
    chooser.Completed += gallery_Completed; 
} 

private void gallery_click(object sender, EventArgs e) 
{ 
    chooser.Show(); 
} 

private void gallery_Completed(object sender, PhotoResult e) 
{ 
    if (e.TaskResult == TaskResult.OK) 
    { 
     BitmapImage tmpBitmap = new BitmapImage(); 
     tmpBitmap.SetSource(e.ChosenPhoto); 
     mtpImg.Source = tmpBitmap; 
    } 
} 
+0

這樣設置opacity = 1表示誰le形象。我需要的是對於幀內部可見的圖像部分,不透明度= 1。 – Dev 2014-10-01 07:21:09

相關問題