gpt4 book ai didi

c# - 如何从代码后面设置 PathIcon?

转载 作者:太空宇宙 更新时间:2023-11-03 21:29:02 24 4
gpt4 key购买 nike

如何在代码隐藏中编写以下 XAML?我在理解其中的 PathIcon 数据部分时遇到问题。

<AppBarToggleButton Label="PathIcon" Click="AppBarButton_Click">
<AppBarToggleButton.Icon>
<PathIcon Data="F1 M 20,20L 24,10L 24,24L 5,24"/>
</AppBarToggleButton.Icon>
</AppBarToggleButton>

最佳答案

尝试,

this.appBarButton.Icon = new PathIcon(){ Data = PathMarkupToGeometry(Your xaml data string)};

在这种情况下:xaml 数据字符串是 F1 M 20,20L 24,10L 24,24L 5,24

Geometry PathMarkupToGeometry(string pathMarkup)
{
string xaml =
"<Path " +
"xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>" +
"<Path.Data>" + pathMarkup + "</Path.Data></Path>";
var path = XamlReader.Load(xaml) as Windows.UI.Xaml.Shapes.Path;
// Detach the PathGeometry from the Path
Geometry geometry = path.Data;
path.Data = null;
return geometry;
}

希望这对你有帮助:)

关于c# - 如何从代码后面设置 PathIcon?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25188349/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com