繁体   English   中英

WPF网格背景与图像画笔和可视画笔相结合

[英]wpf grid background with image brush and visual brush combined

我试图将图像设置为窗口的背景。 我想在窗口上应用渐变不透明蒙版,并平铺图像。 到目前为止,我可以选择其中一个,但不能同时选择两个。 这是我la脚的尝试:

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height = "40*" />
            <RowDefinition Height="133*"/>
        </Grid.RowDefinitions>
        <Grid.Resources>
            <Image x:Key="myImage" Source="/GrimshawRibbon;component/Resources/GeometricBackground.png">
                <Image.OpacityMask>
                    <LinearGradientBrush EndPoint = "0.5,0" StartPoint="0.5,1">
                        <GradientStop Color = "#00000000" Offset="0.6"/>
                        <GradientStop Color = "#FF000000" Offset="1"/>
                    </LinearGradientBrush>
                </Image.OpacityMask>
            </Image>
            <ImageBrush x:Key="imageBrush" ImageSource="/GrimshawRibbon;component/Resources/GeometricBackground.png" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,800,800"/>
            <VisualBrush x:Key="myBrush" Visual="{StaticResource myImage}" Stretch="None" TileMode="Tile"/>
        </Grid.Resources>
        <DockPanel LastChildFill = "False" Grid.RowSpan="2" Background="{StaticResource imageBrush}"/>
        <ContentControl x:Name="MainContentControl" Content="{Binding CurrentPageViewModel}" Margin="10" Grid.Row="1"/>
        <Button x:Name="btnCancel" Content="Close" Margin="0,0,90,10" HorizontalAlignment="Right" Width="75" Height="36" VerticalAlignment="Bottom" Command="{Binding CloseWindowCommand, Mode=OneWay}" CommandParameter="{Binding ElementName=win}" Grid.Row="1"/>
        <Button x:Name="button" Content="?" Margin="0,0,170,10" Height="36" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="36" Command="{Binding NavigateToHelpCommand, Mode=OneWay}" Grid.Row="1"/>
        <Label x:Name="label" Content="Some label" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" FontWeight="Bold" FontSize="14"/>
        <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="10,39,0,0" TextWrapping="Wrap" Text="Some tool description that is not too long. It would be good to keep it under two sentences." VerticalAlignment="Top" Height="36" Width="272"/>
    </Grid>

您可以分配DockPanel的OpacityMask

<DockPanel Grid.RowSpan="2" Background="{StaticResource imageBrush}">
    <DockPanel.OpacityMask>
        <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
            <GradientStop Color="#00000000" Offset="0.6"/>
            <GradientStop Color="#FF000000" Offset="1"/>
        </LinearGradientBrush>
    </DockPanel.OpacityMask>
</DockPanel>

或者可能只是将Rectangle用于背景图像:

<Rectangle Grid.RowSpan="2" Fill="{StaticResource imageBrush}">
    <Rectangle.OpacityMask>
        <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
            <GradientStop Color="#00000000" Offset="0.6"/>
            <GradientStop Color="#FF000000" Offset="1"/>
        </LinearGradientBrush>
    </Rectangle.OpacityMask>
</Rectangle>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM