StackPanel具有圆形和降级背景

时间:2011-06-21 10:14:57

标签: wpf xaml

我正在尝试创建一个带有圆角背景的堆叠面板,它还有一个从灰色到透明的线性画笔

我使用这里暴露的想法来防止剪辑 http://chriscavanagh.wordpress.com/2008/10/03/wpf-easy-rounded-corners-for-anything/

现在的问题是,stackpanel内的文本也有退化,然后变为不可见

任何帮助?

类似的问题 How do I create a WPF Rounded Corner container?

代码:

<Border Margin="235,78,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" 
BorderBrush="Red" BorderThickness="1" CornerRadius="8" >
    <Grid>
    <Border Name="mask" CornerRadius="7">
    <Border.Background>
    <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
       <GradientStop Color="Gray" Offset="0"/>
       <GradientStop Color="Transparent" Offset="1"/>
      </LinearGradientBrush>
    </Border.Background>
    </Border>   
    <StackPanel Orientation="Horizontal" >
     <StackPanel.OpacityMask>
             <VisualBrush Visual="{Binding ElementName=mask}"/>
     </StackPanel.OpacityMask>
    <Image Height="16" Width="16" RenderOptions.BitmapScalingMode="NearestNeighbor" />                     
                <TextBlock Foreground="Black" Margin="5,0,3,0" Text="00620"/>
                <TextBlock Foreground="Black" Margin="5,0,3,0" Text="Error sincronización" />
    </StackPanel>
    </Grid>
    </Border>

1 个答案:

答案 0 :(得分:1)

这是由于OpacityMask,尝试从您的XAML 删除这些行:

<StackPanel.OpacityMask>
             <VisualBrush Visual="{Binding ElementName=mask}"/>
     </StackPanel.OpacityMask>

它应该可行