1

WinRT XAML Toolkit Chart Control의 범례 항목에 스타일을 지정하고 싶습니다. WinRT XAML Toolkit 차트 컨트롤 : 범례 스타일을 지정하는 방법은 무엇입니까?

나는 소스 코드를 확인하고 다음과 같은 스타일의 발견 :

<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> 

을하지만,이 스타일 전설 컨테이너와 제목 만.

어떻게 범례 항목의 스타일을 지정할 수 있습니까 ??

편집 : 감사 답변을 많이 필립, 이것은 내가 원하는 정확히입니다. 하지만 비주얼 스튜디오에서 나에게 오류를 준 :

<Setter.Value> 
        <ItemsPanelTemplate> 
         <controls:UniformGrid 
          Columns="1" 
          Rows="5" /> 
        </ItemsPanelTemplate> 
       </Setter.Value> 

그것은 컨트롤을했다 : UniformGrid를 찾을 수 없습니다, 나는이 부분을 제거하고 작업 일을 얻을 수 있었다.

답변

4

우선주의 할 점은 Legend 컨트롤이 ItemsControl이므로 ItemContainerStyle을 사용하여 항목의 스타일을 지정할 수 있다는 점입니다. 아이템 템플릿은 소스에서 찾을 수있는 LegendItem 스타일의 관리를받습니다. 응용 프로그램에서 모두 스타일을 지정하는 방법은 Chart 컨트롤의 LegendStyle 속성을 설정하여 LegendStyle을 설정하는 것입니다. 그런 다음 Legend 스타일은 ItemContainerStyle에서 Style까지 LegendItem으로 설정합니다. Chart 컨트롤이 블렌드에서 올바르게 작동하는지 확인하지 않았지만 컨트롤이있는 경우 편집하는 것이 가장 좋습니다. 나는이 샘플을 수작업으로 만들었다.

enter image description here

<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> 
관련 문제