2016-12-24 115 views
0

嗨,我試圖改變圖像的透明部分的顏色。請參考圖像 其實我在網格中使用它作爲背景圖像有什麼方法可以改變只有圖像外部的顏色即透明部分,對不透明圖像的主要部分不應施加任何影響。在「FwdBtn」圖像的外部Tap上,主圖像的外部透明部分應該改變。 的XAML試圖改變圖像中的透明部分的顏色

<Grid.Background> 

      <ImageBrush x:Name="imgbg" ImageSource="Assets/LearnColor/bg.png" 
         /> 
     </Grid.Background> 
     <Grid.RowDefinitions> 
      <RowDefinition x:Name="rowDefHeaderPanel" Height="1*"/> 
      <RowDefinition x:Name="rowDefContentPanel" Height="3*"/> 
      <RowDefinition x:Name="rowDefFooterPanel" Height="1*"/> 
     </Grid.RowDefinitions> 
     <RelativePanel x:Name="Headerpanel" Grid.Row="0" Margin="0,0,0,0"> 
      <Image x:Name="prevBtn" 
      Source="Assets/LearnColor/Button/btn_previous_arrow.png" 
       RelativePanel.AlignLeftWithPanel="True" 
       Margin="0,33,-246,23" 
       Tapped="BckImgChng" HorizontalAlignment="Right" Width="88" d:LayoutOverrides="Height"/> 
      <Image x:Name="FwdBtn" 
      Source="Assets/LearnColor/Button/btn_next_arrow.png"    
       Height="88" 
       RelativePanel.AlignRightWithPanel="True" 
       Margin="-152,0,250,-121" 
       Tapped="FwdImgChng" VerticalAlignment="Bottom" d:LayoutOverrides="HorizontalAlignment"/> 
      <Image x:Name="Header" 
      Source="Assets/LearnColor/Header/_0000_header_0.png" Width="440" 
       RelativePanel.AlignVerticalCenterWithPanel="True"     
       Margin="0,-39,-814,-62" HorizontalAlignment="Right"    
       > 
       <Image.Triggers> 
        <EventTrigger RoutedEvent="Image.Loaded"> 
         <BeginStoryboard> 
          <Storyboard x:Name="Blinkopr"> 
           <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" AutoReverse="True" Duration="0:0:0.9" RepeatBehavior="Forever" 
               Storyboard.TargetName="Header"/> 
          </Storyboard> 
         </BeginStoryboard> 

        </EventTrigger> 
       </Image.Triggers> 
      </Image> 
      <TextBlock x:Name="HeaderName" 
       Text="Yellow" 
         FontFamily="Font/BALLOON.TTF#BALLOON" 
       RelativePanel.AlignVerticalCenterWithPanel="True"     
       Margin="543,13,-273,7" Foreground="White" FontSize="25" FontStyle="Normal" FontWeight="ExtraBold" /> 

     </RelativePanel> 

C#代碼

private void FwdImgChng(object sender, TappedRoutedEventArgs e) 
     { 
      //if (currentIndex == 11) 
      //{ return; } 
      currentIndex++; 
      if (currentIndex > 10) 
      { 
       currentIndex = 10; 
       return; 
      } 

      Header.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Header/_0000_header_" + currentIndex + ".png")); 
      image.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Object/ob_" + currentIndex + "_0.png")); 
      prevObjBtn.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Button/prev" + currentIndex + ".png")); 
      fwdObjBtn.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Button/next" + currentIndex + ".png")); 
      HeaderName.Text = Headername[currentIndex];    
      objNameWritten.Text = objnamewritten[currentIndex]; 
      objNameWritten.Foreground = new SolidColorBrush(HColorname[currentIndex]); 
      mediaElement1.Source = new Uri("ms-appx:///Assets/LearnColor/Objectnamesmp3/C" + currentIndex + ".mp3"); 
      //mediaElement1.AutoPlay = true; 


     } 

圖片enter image description here

回答

1

把你的網格中的另一個控件內部設置的背景下,你可以使用例如我用你喜歡的任何控制,另一個網格在這裏:

<Grid Background="#c0c0c0"> 
<!-- Your grid here--> 
</Grid> 
+0

嗨,我正在嘗試像這樣的相同圖像ü提到<網格X:名稱= 「Mainbg」> <網格X:名稱= 「2ndgrid」> <圖像刷X:名稱= 「imgbg」 的ImageSource = 「資產/ bg.png」/> <按鈕X:名稱= 「BTN」 的Horizo​​ntalAlignment = 「中心」 螺紋= 「btnTap」> C#代碼私人無效btnTap(對象發件人,TappedRoutedEventArgs E) { Mainbg.Background = new SolidColorBrush(Colors.Cyan); Mainbg.Background = new SolidColorBrush(Colors.Cyan); }但給出錯誤的任何分辨率 – anuj

+0

@anuj錯誤是什麼? – Emad

+0

@Edmad它的工作實際上,我不應該給第二個網格名稱爲「2ndgrid」。當我改變它的名稱時,它的格式不正確。 – anuj