Windows runtime WinRT XAML工具箱图表控件:如何设置图例项的样式?

Windows runtime WinRT XAML工具箱图表控件:如何设置图例项的样式?,windows-runtime,windows-store-apps,winrt-xaml,silverlight-toolkit,winrt-xaml-toolkit,Windows Runtime,Windows Store Apps,Winrt Xaml,Silverlight Toolkit,Winrt Xaml Toolkit,我想设置WinRT XAML工具箱图表控件的图例项的样式 我检查了源代码,发现以下样式: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:datavis="using:WinRTXamlToolkit.Controls.Da

我想设置WinRT XAML工具箱图表控件的图例项的样式

我检查了源代码,发现以下样式:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:datavis="using:WinRTXamlToolkit.Controls.DataVisualization">

    <Style
        TargetType="datavis:Legend">
        <Setter
            Property="BorderBrush"
            Value="Black" />
        <Setter
            Property="BorderThickness"
            Value="1" />
        <Setter
            Property="IsTabStop"
            Value="False" />
        <Setter
            Property="TitleStyle">
            <Setter.Value>
                <Style
                    TargetType="datavis:Title">
                    <Setter
                        Property="Margin"
                        Value="0,5,0,10" />
                    <Setter
                        Property="FontWeight"
                        Value="Bold" />
                    <Setter
                        Property="HorizontalAlignment"
                        Value="Center" />
                </Style>
            </Setter.Value>
        </Setter>
        <Setter
            Property="Template">
            <Setter.Value>
                <ControlTemplate
                    TargetType="datavis:Legend">
                    <Border
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Padding="2">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition
                                    Height="Auto" />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <datavis:Title
                                Grid.Row="0"
                                x:Name="HeaderContent"
                                Content="{TemplateBinding Header}"
                                ContentTemplate="{TemplateBinding HeaderTemplate}"
                                Style="{TemplateBinding TitleStyle}" />
                            <ScrollViewer
                                Grid.Row="1"
                                VerticalScrollBarVisibility="Auto"
                                BorderThickness="0"
                                Padding="0"
                                IsTabStop="False">
                                <ItemsPresenter
                                    x:Name="Items"
                                    Margin="10,0,10,10" />
                            </ScrollViewer>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

但这仅为图例容器和标题设置样式

如何设置图例项目的样式

编辑: 非常感谢菲利普的回答,这正是我想要的。 但是Visual Studio在以下位置给了我一个错误:



它说没有找到控件:UniformGrid,我删除了此部分并设法使其正常工作。

首先要注意的是
图例
控件是一个
项控件
,因此可以使用
项容器样式设置其项的样式。项目模板由
LegendItem
样式管理,您也可以在源代码中找到该样式。在应用程序中设置所有样式的方法是通过在
图表
控件上设置
LegendStyle
属性来设置
图例
样式。然后在
Legend
样式集
ItemContainerStyle
中设置为
LegendItem
style
。我还没有检查
图表
控件在Blend中的行为是否正确,但如果正确,那将是编辑这些控件的最佳位置。我只是手工制作了这个样品

<charting:Chart
    x:Name="PieChart"
    Title="Pie Chart"
    Margin="70,0">
    <charting:Chart.Series>
        <Series:PieSeries
            Title="Population"
            ItemsSource="{Binding Items}"
            IndependentValueBinding="{Binding Name}"
            DependentValueBinding="{Binding Value}"
            IsSelectionEnabled="True" />
    </charting:Chart.Series>
    <charting:Chart.LegendStyle>
        <Style
            TargetType="datavis:Legend">
            <Setter
                Property="VerticalAlignment"
                Value="Stretch" />
            <Setter
                Property="Background"
                Value="#444" />
            <Setter
                Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <controls:UniformGrid
                            Columns="1"
                            Rows="5" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter
                Property="TitleStyle">
                <Setter.Value>
                    <Style
                        TargetType="datavis:Title">
                        <Setter
                            Property="Margin"
                            Value="0,5,0,10" />
                        <Setter
                            Property="FontWeight"
                            Value="Bold" />
                        <Setter
                            Property="HorizontalAlignment"
                            Value="Center" />
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter
                Property="ItemContainerStyle"
                xmlns:series="using:WinRTXamlToolkit.Controls.DataVisualization.Charting">
                <Setter.Value>
                    <Style
                        TargetType="series:LegendItem">
                        <Setter
                            Property="Template">
                            <Setter.Value>
                                <ControlTemplate
                                    TargetType="series:LegendItem">
                                    <Border
                                        MinWidth="200"
                                        Margin="20,10"
                                        CornerRadius="10"
                                        VerticalAlignment="Stretch"
                                        HorizontalAlignment="Stretch"
                                        Background="{Binding Background}">
                                        <datavis:Title
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Center"
                                            FontSize="24"
                                            FontWeight="Bold"
                                            Content="{TemplateBinding Content}" />
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter
                Property="Template">
                <Setter.Value>
                    <ControlTemplate
                        TargetType="datavis:Legend">
                        <Border
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Padding="2">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition
                                        Height="Auto" />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <datavis:Title
                                    Grid.Row="0"
                                    x:Name="HeaderContent"
                                    Content="{TemplateBinding Header}"
                                    ContentTemplate="{TemplateBinding HeaderTemplate}"
                                    Style="{TemplateBinding TitleStyle}" />
                                <ScrollViewer
                                    Grid.Row="1"
                                    VerticalScrollBarVisibility="Auto"
                                    BorderThickness="0"
                                    Padding="0"
                                    IsTabStop="False">
                                    <ItemsPresenter
                                        x:Name="Items"
                                        Margin="10,0,10,10" />
                                </ScrollViewer>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </charting:Chart.LegendStyle>
</charting:Chart>


<charting:Chart
    x:Name="PieChart"
    Title="Pie Chart"
    Margin="70,0">
    <charting:Chart.Series>
        <Series:PieSeries
            Title="Population"
            ItemsSource="{Binding Items}"
            IndependentValueBinding="{Binding Name}"
            DependentValueBinding="{Binding Value}"
            IsSelectionEnabled="True" />
    </charting:Chart.Series>
    <charting:Chart.LegendStyle>
        <Style
            TargetType="datavis:Legend">
            <Setter
                Property="VerticalAlignment"
                Value="Stretch" />
            <Setter
                Property="Background"
                Value="#444" />
            <Setter
                Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <controls:UniformGrid
                            Columns="1"
                            Rows="5" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter
                Property="TitleStyle">
                <Setter.Value>
                    <Style
                        TargetType="datavis:Title">
                        <Setter
                            Property="Margin"
                            Value="0,5,0,10" />
                        <Setter
                            Property="FontWeight"
                            Value="Bold" />
                        <Setter
                            Property="HorizontalAlignment"
                            Value="Center" />
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter
                Property="ItemContainerStyle"
                xmlns:series="using:WinRTXamlToolkit.Controls.DataVisualization.Charting">
                <Setter.Value>
                    <Style
                        TargetType="series:LegendItem">
                        <Setter
                            Property="Template">
                            <Setter.Value>
                                <ControlTemplate
                                    TargetType="series:LegendItem">
                                    <Border
                                        MinWidth="200"
                                        Margin="20,10"
                                        CornerRadius="10"
                                        VerticalAlignment="Stretch"
                                        HorizontalAlignment="Stretch"
                                        Background="{Binding Background}">
                                        <datavis:Title
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Center"
                                            FontSize="24"
                                            FontWeight="Bold"
                                            Content="{TemplateBinding Content}" />
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter
                Property="Template">
                <Setter.Value>
                    <ControlTemplate
                        TargetType="datavis:Legend">
                        <Border
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Padding="2">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition
                                        Height="Auto" />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <datavis:Title
                                    Grid.Row="0"
                                    x:Name="HeaderContent"
                                    Content="{TemplateBinding Header}"
                                    ContentTemplate="{TemplateBinding HeaderTemplate}"
                                    Style="{TemplateBinding TitleStyle}" />
                                <ScrollViewer
                                    Grid.Row="1"
                                    VerticalScrollBarVisibility="Auto"
                                    BorderThickness="0"
                                    Padding="0"
                                    IsTabStop="False">
                                    <ItemsPresenter
                                        x:Name="Items"
                                        Margin="10,0,10,10" />
                                </ScrollViewer>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </charting:Chart.LegendStyle>
</charting:Chart>