如何将按钮的样式更改为Path对象?

时间:2014-01-24 15:39:32

标签: wpf button path styles windows-store-apps

将WPF用于Windows应用商店应用:

我正在寻找将Path对象的形状作为Button的外观的可能性。

Path path = new Path();
Button btn = new Button();
btn.Style = path.Style; // searching for something like this

编辑: 我用这样的Button.Content尝试过,但也失败了:

<Button>
    <Button.Content>
        <Path>
            <Path.Data>
                <PathGeometry>
                    <PathFigure StartPoint="0,0">
                        <ArcSegment Point="200,0"
                            IsLargeArc="False"
                            RotationAngle="180"
                            Size="200,200"
                            SweepDirection="Clockwise"
                        />
                        <LineSegment Point="0,0"/>
....Leaving all the Closing Tags

这不应该给我一个半圆形的按钮吗?在VisualStudio中,我仍然可以获得矩形按钮。

1 个答案:

答案 0 :(得分:1)

在XAML中:

<Button>
    <Button.Content>
        <Path Data="path data here..."/>
    </Button.Content>
</Button>

在代码中,您希望将按钮的内容设置为您想要显示的内容。

Button myButton = new Button();
Path myPath = new Path();
myPath.Data = ...
myButton.Content = myPath;

请帮自己一个忙,并获得一本关于Windows应用商店应用开发的书。我强烈推荐Pete Brown的这项工作: http://www.amazon.com/Windows-Store-App-Development-XAML/dp/1617290947

在拯救你的时候,它将不仅仅能为自己付出代价。无论是在WPF / Silverlight / Windows Phone / Windows Store应用程序中使用XAML进行开发都与开发应用程序的传统方式有很大不同。

干杯, 戴夫