多边形中的VisualBrush

问题描述:

我有这个控制权:

I have this control:


多边形不是正方形,但是我试图在多边形的边缘绘制边框,这意味着右上角像素将位于多边形(100,10)的右上角,与右下角相同(100,90),它不会剪切图像.

The Polygon is not a square but I am trying to make the border be drawn on the edge of the Polygon, meaning that the top right pixel will be at the top right point of the polygon (100,10), same with the bottom right (100,90) and it won't cut the image.

在我的情况下,没有边框,而是带有内容的完整网格,边框仅用于示例.

In my case there is no border but a full grid with content, the Border is just for the example.

嗨Itamar Epstein,
>>多边形"不是正方形,但我正在尝试在多边形"的边缘绘制边框
如果您需要这样的东西:

Hi Itamar Epstein,
>>The Polygon is not a square but I am trying to make the border be drawn on the edge of the Polygon
If you need something like this:

您可以使用Stroke:

You could use Stroke :

    <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
        <Border x:Name="MainBorder" BorderBrush="Blue" Background="Gray" Height="100" Width="100">
            <TextBlock Foreground="Black" FontSize="35" HorizontalAlignment="Center"> 
                    <Run Text="Test"/>
                    <LineBreak/>
                    <Run Text="Test"/>
            </TextBlock>
        </Border>
        <Polygon Stroke="Blue" StrokeThickness="3" Points="0,0 100,10 100,90 0,100" Margin="0,20,0,0">
            <Polygon.Fill>
                <VisualBrush Visual="{Binding ElementName=MainBorder}" Stretch="Fill"/>
            </Polygon.Fill>
        </Polygon>
    </StackPanel>

最好的问候,

Annievia Chen

Annievia Chen