【问题标题】:How to change the styling of Buttons to a Path object?如何将 Button 的样式更改为 Path 对象?
【发布时间】:2014-01-24 15:39:32
【问题描述】:

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

我正在寻找一种可能性,将我的 Path 对象的形状作为按钮的外观。

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 中,我仍然得到矩形按钮。

【问题讨论】:

  • 你能详细写下你需要什么吗? Path 到按钮,是在Button.Content 还是在Button 模板中?显示您的 XAML。
  • 第一,没有WPF for Windows Store Apps这样的东西。您一定在谈论不是 WPF 的 WinRT XAML。第二,不要在程序代码中创建或操作 UI 元素。这就是 XAML 的用途。

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


【解决方案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 进行开发,都与传统的应用程序开发方式有很大不同。

干杯, 戴夫

【讨论】:

    猜你喜欢
    • 2015-10-02
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 2011-03-30
    • 2021-06-21
    • 2021-04-26
    • 1970-01-01
    • 2012-03-28
    相关资源
    最近更新 更多