2

在我的 xaml 页面中,我有一种样式和一种画笔,如下所示 -

<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:BaseView}, 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 x:Key="ICON_BRUSH">
<DrawingBrush.Drawing>
  <DrawingGroup>
    <GeometryDrawing Brush="Gray" Geometry="F1 M0,25 L25,50, 50,25 25,0z">
      <GeometryDrawing.Pen>
        <Pen DashCap="Triangle" EndLineCap="Flat" LineJoin="Bevel" MiterLimit="10" StartLineCap="Flat" Thickness="5">
          <Pen.Brush>
            <LinearGradientBrush>
              <GradientStop Color="Red" Offset="0"/>
              <GradientStop Color="Green" Offset="1"/>
            </LinearGradientBrush>
          </Pen.Brush>
          <Pen.DashStyle>
            <DashStyle/>
          </Pen.DashStyle>
        </Pen>
      </GeometryDrawing.Pen>
    </GeometryDrawing>
  </DrawingGroup>
</DrawingBrush.Drawing>

我如何将这两者结合成一种风格。我尝试了以下方法,但没有奏效。

<Style x:Key="COMBINED_NODE_ICON" TargetType="Rectangle" BasedOn="{StaticResource ICON_STYLE}">
<Setter Property="Fill">
  <Setter.Value>
    <DrawingBrush TileMode="None">
      <DrawingBrush.Drawing>
          <DrawingGroup>
            <DrawingGroup.Transform>
              <TranslateTransform X="0.2" Y="0.2" />
            </DrawingGroup.Transform>
            <GeometryDrawing Brush="{StaticResource ICON_BRUSH}">
              <GeometryDrawing.Geometry>
                <RectangleGeometry Rect="0,0,1,1" />
              </GeometryDrawing.Geometry>
            </GeometryDrawing>
        </DrawingGroup>
      </DrawingBrush.Drawing>
    </DrawingBrush>
  </Setter.Value>
</Setter>

任何帮助将不胜感激。谢谢。

4

1 回答 1

1

这应该有效(dkozl plus BasedOn):

<Style x:Key="COMBINED_NODE_ICON"
       TargetType="Rectangle"
       BasedOn="{StaticResource ICON_STYLE}">
    <Setter Property="Fill"
            Value="{StaticResource ICON_BRUSH}" />
</Style>

BasedOn只要您的基本样式 (ICON_STYLE) 仅包含 , 就可以省略该部分(纯 dkozl) Fill Setter,因为该Fill属性在样式 COMBINED_NODE_ICON 中被覆盖。

而且你的代码也可以工作,如果你添加最后一行

<DrawingBrush x:Key="ICON_BRUSH">
    ...
</DrawingBrush>

和最后一行

<Style x:Key="COMBINED_NODE_ICON" TargetType="Rectangle" BasedOn="{StaticResource ICON_STYLE}">
    ...
</Style>
于 2016-03-25T13:44:25.050 回答