我目前面临的问题是样式化WPF的TreeViewItem(或者它的扩展器是精确的),当我从PNG文件中放入一个ImageSource时,它正在显示,但正如预期的那样锯齿状。所以我用DrawingImage替换它并没有出现。
这是Expander的模板。大部分代码都来自SimpleStyles.xaml,包括Blend。 (TreeViewItem本身似乎很好):
<Style x:Name="Expander" d:IsControlPart="True" TargetType="ToggleButton">
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Grid Width="15" Height="13" Background="Transparent">
<Image HorizontalAlignment="Left" Margin="1,1,1,1" VerticalAlignment="Center" Visibility="Collapsed" x:Name="IsExpandedPath">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup ClipGeometry="M0,0 V476,25 H806,06 V0 H0 Z">
<GeometryDrawing Brush="#FF000000" Geometry="F1 M476.25,806.06z M0,0z M238.25,-0.11L238.25,-0.11 238.13,0 238,-0.11z" />
<GeometryDrawing Brush="#FFFFFFFF" Geometry="F1 M476.25,806.06z M0,0z M238.12,806.06L238.12,806.06 238.25,806.39 238,806.36z">
<GeometryDrawing.Pen>
<Pen Brush="#FF000000" Thickness="1" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter" MiterLimit="10" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Brush="#FF000000" Geometry="F1 M476.25,806.06z M0,0z M238.13,0L0,211.44 238.12,806.06 476.25,211.44 238.13,0z M238,353.89L73,206.89 238,59.89 403.17,206.89 238,353.89z" />
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
<Image HorizontalAlignment="Left" Margin="1,1,1,1" VerticalAlignment="Center" x:Name="ExpandPath">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup ClipGeometry="M0,0 V476,25 H806,06 V0 H0 Z">
<GeometryDrawing Brush="#FF000000" Geometry="F1 M476.25,806.06z M0,0z M238.25,-0.11L238.25,-0.11 238.13,0 238,-0.11z" />
<GeometryDrawing Brush="#FFFFFFFF" Geometry="F1 M476.25,806.06z M0,0z M238.12,806.06L238.12,806.06 238.25,806.39 238,806.36z">
<GeometryDrawing.Pen>
<Pen Brush="#FF000000" Thickness="1" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter" MiterLimit="10" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Brush="#FF000000" Geometry="F1 M476.25,806.06z M0,0z M238.13,0L0,122.057 238.12,806.06 476.25,122.057 238.13,0z M238,220.39L73,122.529 238,24.668 403.17,122.529 238,220.39z" />
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Visibility" Value="Visible" TargetName="IsExpandedPath"/>
<Setter Property="Visibility" Value="Collapsed" TargetName="ExpandPath"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
答案 0 :(得分:2)
我在一个独立的ToggleButton
中对此进行了测试。如果我从ClipGeometry
元素中删除DrawingGroup
属性,它对我有用:
<Image HorizontalAlignment="Left" Margin="1,1,1,1" VerticalAlignment="Center" Visibility="Collapsed" x:Name="IsExpandedPath">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup >
<GeometryDrawing Brush="#FF000000" Geometry="F1 M476.25,806.06z M0,0z M238.25,-0.11L238.25,-0.11 238.13,0 238,-0.11z" />
<GeometryDrawing Brush="#FFFFFFFF" Geometry="F1 M476.25,806.06z M0,0z M238.12,806.06L238.12,806.06 238.25,806.39 238,806.36z">
<GeometryDrawing.Pen>
<Pen Brush="#FF000000" Thickness="1" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter" MiterLimit="10" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Brush="#FF000000" Geometry="F1 M476.25,806.06z M0,0z M238.13,0L0,211.44 238.12,806.06 476.25,211.44 238.13,0z M238,353.89L73,206.89 238,59.89 403.17,206.89 238,353.89z" />
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
<Image HorizontalAlignment="Left" Margin="1,1,1,1" VerticalAlignment="Center" x:Name="ExpandPath">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup >
<GeometryDrawing Brush="#FF000000" Geometry="F1 M476.25,806.06z M0,0z M238.25,-0.11L238.25,-0.11 238.13,0 238,-0.11z" />
<GeometryDrawing Brush="#FFFFFFFF" Geometry="F1 M476.25,806.06z M0,0z M238.12,806.06L238.12,806.06 238.25,806.39 238,806.36z">
<GeometryDrawing.Pen>
<Pen Brush="#FF000000" Thickness="1" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter" MiterLimit="10" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Brush="#FF000000" Geometry="F1 M476.25,806.06z M0,0z M238.13,0L0,122.057 238.12,806.06 476.25,122.057 238.13,0z M238,220.39L73,122.529 238,24.668 403.17,122.529 238,220.39z" />
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>