WPF 图表图例项目样式

发布于 2024-09-24 18:38:13 字数 1388 浏览 9 评论 0原文

我正在尝试在 WPF 图表中设置图例项目的样式。我有以下 LegendStyle,但这不会改变任何内容。我做错了什么?

谢谢!

<Style x:Key="LegendStyle1" TargetType="{x:Type datavis:Legend}">
    <Setter Property="ItemContainerStyle">
        <Setter.Value>
            <Style TargetType="charting:LegendItem">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="charting:LegendItem">
                            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                    <Rectangle Width="40" Height="40" Fill="{Binding Background}" Stroke="{Binding BorderBrush}" StrokeThickness="1" VerticalAlignment="Center" />
                                    <datavis:Title Content="{TemplateBinding Content}" VerticalAlignment="Center"/>
                                </StackPanel>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Setter.Value>
    </Setter>
</Style>

I am trying to style the Legend Items in my WPF Chart. I have the following LegendStyle, but this doesn't change anything. What am I doing wrong?

Thanks!

<Style x:Key="LegendStyle1" TargetType="{x:Type datavis:Legend}">
    <Setter Property="ItemContainerStyle">
        <Setter.Value>
            <Style TargetType="charting:LegendItem">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="charting:LegendItem">
                            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                    <Rectangle Width="40" Height="40" Fill="{Binding Background}" Stroke="{Binding BorderBrush}" StrokeThickness="1" VerticalAlignment="Center" />
                                    <datavis:Title Content="{TemplateBinding Content}" VerticalAlignment="Center"/>
                                </StackPanel>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Setter.Value>
    </Setter>
</Style>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2024-10-01 18:38:13

我想也许 TargetType="charting:Legend">

<Style x:Key="LegendStyle1" TargetType="charting:Legend">
    <Setter Property="ItemContainerStyle"> 
        <Setter.Value> 
            <Style TargetType="charting:LegendItem"> 
                <Setter Property="Template"> 
                    <Setter.Value> 
                        <ControlTemplate TargetType="charting:LegendItem"> 
                            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> 
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center"> 
                                    <Rectangle Width="40" Height="40" Fill="{Binding Background}" Stroke="{Binding BorderBrush}" StrokeThickness="1" VerticalAlignment="Center" /> 
                                    <datavis:Title Content="{TemplateBinding Content}" VerticalAlignment="Center"/> 
                                </StackPanel> 
                            </Border> 
                        </ControlTemplate> 
                    </Setter.Value> 
                </Setter> 
            </Style> 
        </Setter.Value> 
    </Setter> 
</Style> 

I think maybe TargetType="charting:Legend">

<Style x:Key="LegendStyle1" TargetType="charting:Legend">
    <Setter Property="ItemContainerStyle"> 
        <Setter.Value> 
            <Style TargetType="charting:LegendItem"> 
                <Setter Property="Template"> 
                    <Setter.Value> 
                        <ControlTemplate TargetType="charting:LegendItem"> 
                            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> 
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center"> 
                                    <Rectangle Width="40" Height="40" Fill="{Binding Background}" Stroke="{Binding BorderBrush}" StrokeThickness="1" VerticalAlignment="Center" /> 
                                    <datavis:Title Content="{TemplateBinding Content}" VerticalAlignment="Center"/> 
                                </StackPanel> 
                            </Border> 
                        </ControlTemplate> 
                    </Setter.Value> 
                </Setter> 
            </Style> 
        </Setter.Value> 
    </Setter> 
</Style> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文