4

我有一个 VisualBrush,我已将 TileMode 属性设置为 Tile。

但是,它不会平铺 - 它会伸展。有人可以帮忙吗?

谢谢

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="test"
    x:Name="UserControl"
    d:DesignWidth="500" d:DesignHeight="500">
    <UserControl.Resources>
        <VisualBrush x:Key="MyBrush" TileMode="Tile">
            <VisualBrush.Visual>
                <Grid Width="20">

                    <Ellipse Fill="#FF00EBFF" Stroke="Black" StrokeThickness="2" Width="20" Height="20" RenderTransformOrigin="0.5,0.5" >
                    </Ellipse>
                </Grid>
            </VisualBrush.Visual>
        </VisualBrush>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" >
    <Grid Background="{StaticResource MyBrush}" />
    </Grid>
</UserControl>
4

1 回答 1

4

尝试这个:

<UserControl x:Class="WpfApplication1.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <VisualBrush x:Key="MyBrush" TileMode="Tile" Viewport="20, 20, 20, 20" ViewportUnits="Absolute">
            <VisualBrush.Visual>
                <Ellipse Fill="#FF00EBFF" Stroke="Black" StrokeThickness="2" Width="20" Height="20" RenderTransformOrigin="0.5,0.5" />
            </VisualBrush.Visual>
        </VisualBrush>
    </UserControl.Resources>
    <Grid>
        <Grid x:Name="LayoutRoot" Background="{StaticResource MyBrush}">

        </Grid>
    </Grid>
</UserControl>

使用 TileMode 时需要指定 ViewPort 值。

于 2012-05-16T14:07:10.540 回答