WinRT XAML Toolkit Charting Controls: How to style Legend Items?
我要设置WinRT XAML工具包图表控件的图例项的样式。
我检查了源代码,发现了以下样式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | <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> |
但这仅用于设置图例容器和标题的样式。
如何设置图例项的样式??
EDIT:
Thanks a lot Filip for the answer, this is exactly what I wanted.
but Visual Studio gave me an error at:
1 2 3 4 5 6 7 | <Setter.Value> <ItemsPanelTemplate> <controls:UniformGrid Columns="1" Rows="5" /> </ItemsPanelTemplate> </Setter.Value> |
上面写着:没有找到制服网格,我移除了这个部分,并设法让事情正常运转。
首先要注意的是,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | <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> |