2016-12-24 123 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