gpt4 book ai didi

c# - 如何从 Xaml 中的 Style 中提取 Setter 值属性?

转载 作者:太空狗 更新时间:2023-10-30 01:32:46 24 4
gpt4 key购买 nike

我有一个样式具有名为“Fill”的 setter 属性,并将 DrawingBrush 作为其值。我想从中提取 DrawingBrush 以在 View 模型中使用。这是我的风格。

<Style x:Key="ICON_STYLE" TargetType="Rectangle">
<Setter Property="Fill">
<Setter.Value>
<DrawingBrush Viewbox="0,0,39.125,39.125" ViewboxUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing Brush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=uiEntityViews:ViewModel}, Path=MeSiteColor}" Geometry="F1M19.5625,0.999954C29.8144,0.999954 38.125,9.31053 38.125,19.5625 38.125,29.8142 29.8143,38.1249 19.5625,38.1249 9.31073,38.1249 1,29.8142 1,19.5625 1,9.31053 9.31064,0.999954 19.5625,0.999954z">
<GeometryDrawing.Pen>
<Pen DashCap="Square" EndLineCap="Flat" LineJoin="Round" MiterLimit="10" StartLineCap="Flat" Thickness="2">
<Pen.Brush>
<LinearGradientBrush EndPoint="0.849422,0.849423" StartPoint="0.150577,0.150578">
<GradientStop Color="#FF657783" Offset="0"/>
<GradientStop Color="White" Offset="0.146"/>
<GradientStop Color="#FF2C4758" Offset="1"/>
</LinearGradientBrush>
</Pen.Brush>
<Pen.DashStyle>
<DashStyle/>
</Pen.DashStyle>
</Pen>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Setter.Value>
</Setter>
</Style>

我想提取 DrawingBrush 如下 -

if (resourceObject is Style)
{
Style iconStyle = resourceObject as Style;
var collections = iconStyle.Setters;
// How to extract iconBrush from collections????
DrawingBrush iconBrush = ???
}

最佳答案

以下可能有效:

DrawingBrush iconBrush = GrabFirstDrawingBrushInStyle(resourceObject as Style);

private DrawingBrush GrabFirstDrawingBrushInStyle(Style style)
{
if (style != null)
{
foreach (var setter in style.Setters.OfType<Setter>())
{
if (setter.Value is DrawingBrush)
return (DrawingBrush)setter.Value;
}
}
return null;
}

关于c# - 如何从 Xaml 中的 Style 中提取 Setter 值属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36181104/

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