将图例项显示为两列

时间:2018-03-13 01:39:49

标签: wpf data-visualization wpftoolkit

我正在使用WpfToolkit绘制饼图,我喜欢将我的传奇展示到两列,因为我的传说很多,我该如何解决?

<chartingToolkit:Chart Height="auto" x:Name="PieChart2" Title="{Binding}"  
        VerticalAlignment="Top" Grid.Row="0" Grid.ColumnSpan="3" Margin="5" LegendTitle="Label" >
            <chartingToolkit:PieSeries DependentValuePath="Value"
        IndependentValuePath="Key" ItemsSource="{Binding}">
            </chartingToolkit:PieSeries>
            <charting:Chart.LegendStyle>
                <Style TargetType="datavis:Legend">
                    <Setter Property="HorizontalAlignment" Value="Stretch"/>
                </Style>
            </charting:Chart.LegendStyle>
        </chartingToolkit:Chart>

提前致谢!

1 个答案:

答案 0 :(得分:0)

根据您的需要,我已将Legend的ControlTemplate更改为如下所示

  <ControlTemplate x:Key="LegendControlTemplate1"
                     TargetType="{x:Type visualizationToolkit:Legend}">
        <Border BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                Background="{TemplateBinding Background}"
                Padding="2">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <visualizationToolkit:Title x:Name="HeaderContent"
                                            ContentTemplate="{TemplateBinding HeaderTemplate}"
                                            Content="{TemplateBinding Header}"
                                            Grid.Row="0"
                                            Style="{TemplateBinding TitleStyle}" />
                <ScrollViewer BorderThickness="0"
                              IsTabStop="False"
                              Padding="0"
                              Grid.Row="1"
                              VerticalScrollBarVisibility="Auto">
                    <!--<ItemsPresenter  x:Name="Items"
                                    Margin="10,0,10,10" >
                    </ItemsPresenter>-->
                    <ItemsControl x:Name="Items"
                                  Margin="10,0,10,10"
                                  ItemsSource="{TemplateBinding ItemsSource}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <UniformGrid Columns="2" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>

                </ScrollViewer>
            </Grid>
        </Border>
    </ControlTemplate>

我不确定这是否符合您的要求。如果满意,请将其标记为答案。