Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 结合图像笔刷和视觉笔刷的wpf网格背景_C#_Wpf_Imagebrush_Visualbrush - Fatal编程技术网

C# 结合图像笔刷和视觉笔刷的wpf网格背景

C# 结合图像笔刷和视觉笔刷的wpf网格背景,c#,wpf,imagebrush,visualbrush,C#,Wpf,Imagebrush,Visualbrush,我正在尝试将图像设置为窗口的背景。我想在窗口上应用渐变不透明度遮罩,并将图像平铺。到目前为止,我可以选择其中之一,但不能同时选择两者。以下是我在这方面的拙劣尝试: <Grid> <Grid.RowDefinitions> <RowDefinition Height = "40*" /> <RowDefinition Height="133*"/> </Grid.R

我正在尝试将图像设置为窗口的背景。我想在窗口上应用渐变不透明度遮罩,并将图像平铺。到目前为止,我可以选择其中之一,但不能同时选择两者。以下是我在这方面的拙劣尝试:

<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的不透明掩码:

或者可能只使用一个矩形作为背景图像:

<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>
<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>