VisualBrush在WPF中具有渐弱的边距

时间:2014-02-16 22:20:44

标签: wpf visualbrush

我试图创建一个带有阴影图案的VisualBrush,它会在顶部和底部边缘处淡出。虽然我对孵化本身没有任何问题:

<VisualBrush x:Key="b1" TileMode="Tile" Viewport="0,0,15,15" ViewportUnits="Absolute" Viewbox="0,0,15,15" ViewboxUnits="Absolute">
    <VisualBrush.Visual>
        <Canvas>
            <Path Data="M 0 15 L 15 0" Stroke="Gray"></Path>
            <Path Data="M 0 0 L 15 15" Stroke="Gray"></Path>
        </Canvas>
    </VisualBrush.Visual>    
</VisualBrush>

我真的没有办法让它褪色。知道怎么做吗?

尝试按下图所示获取背景。

enter image description here

1 个答案:

答案 0 :(得分:0)

据我从示例图片中了解到,您需要指定一般Background。为此我设置Grid而不是Canvas并为他设置Background颜色。

对于将显示需要设置OpasityMask的内容的面板,如下所示:

<Window.Resources>
    <VisualBrush x:Key="b1" TileMode="Tile" Viewport="0,0,15,15" ViewportUnits="Absolute" Viewbox="0,0,15,15" ViewboxUnits="Absolute">
        <VisualBrush.Visual>
            <Grid Background="Black">
                <Path Data="M 0 15 L 15 0" Stroke="Gray" />
                <Path Data="M 0 0 L 15 15" Stroke="Gray" />
            </Grid>
        </VisualBrush.Visual>
    </VisualBrush>
</Window.Resources>

<Grid Background="{StaticResource b1}">
    <Grid.OpacityMask>
        <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
            <GradientStop Offset="0" Color="Black" />
            <GradientStop Offset="1" Color="Transparent" />
        </LinearGradientBrush>
    </Grid.OpacityMask>

    <Label Content="TEST" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>

<强> Result

enter image description here