Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Wpf 旋转六边形按钮,但不要旋转图像_Wpf - Fatal编程技术网

Wpf 旋转六边形按钮,但不要旋转图像

Wpf 旋转六边形按钮,但不要旋转图像,wpf,Wpf,我有按钮和形状(六边形)在它里面,我想旋转。但我不希望它的背景被旋转。 如何将图像放置到旋转的六边形按钮? 这是我的密码: <Button Height="182" Width="155" RenderTransformOrigin="0.5,1.368"> <Button.Background> <ImageBrush ImageSource="mob.png"/> </Button.Background>

我有按钮和形状(六边形)在它里面,我想旋转。但我不希望它的背景被旋转。 如何将图像放置到旋转的六边形按钮? 这是我的密码:

<Button Height="182" Width="155" RenderTransformOrigin="0.5,1.368">
    <Button.Background>
        <ImageBrush ImageSource="mob.png"/>
    </Button.Background>
    <Button.RenderTransform>
        <TransformGroup>
            <ScaleTransform/>
            <SkewTransform/>
            <RotateTransform Angle="270"/>
            <TranslateTransform X="187.488" Y="-187.488"/>
        </TransformGroup>
    </Button.RenderTransform>

    <Button.Template>
        <ControlTemplate>
              <ed:RegularPolygon Fill="{TemplateBinding Background}"/>
          </ControlTemplate>
     </Button.Template>
 </Button>

我可以建议您创建一个ControlTemplate来处理您在这里需要的所有内容吗

在模板中,确保绘制多边形,然后将其旋转到所需的任何值,然后将ContentPresenter控件添加到模板中。这应该画出你的按钮的内容是什么。在您的cas中,eI会将mod.png作为内容

绑定ContentPrester需要使用TemplateBinding,如下所示

<!-- DRAW HEXAGON HERE -->
<ContentPresenter Conent="{TemplateBinding Content}"/>


并确保对六边形而不是内容应用任何旋转。

使用按钮上的“渲染变换”(RenderTransform)无法执行此操作,因为这样会旋转整个填充多边形。可以使用带有包含多段线的几何图形的
路径,而不是
ed:RegularPolygon
,例如
PathGeometry

<Button Height="182" Width="155">
    <Button.Background>
        <ImageBrush ImageSource="mob.png"/>
    </Button.Background>

    <Button.Template>
        <ControlTemplate>
            <Path Fill="{TemplateBinding Background}">
                <Path.Data>
                    <PathGeometry>
                        <PathGeometry.Transform>
                            ... put transform here ...
                        </PathGeometry.Transform>
                        <PathGeometry.Figures>
                            ... put polyline data here ...
                        </PathGeometry.Figures>
                    </PathGeometry>
                </Path.Data>
            </Path>
        </ControlTemplate>
    </Button.Template>
</Button>

... 把变换放在这里。。。
... 将多段线数据放在这里。。。

很抱歉,要获得您想要的东西有点困难,您希望多边形具有渲染变换而不是整个按钮吗?