【问题标题】:Move Silverlight Chart Legend Below ChartArea将 Silverlight 图表图例移到 ChartArea 下方
【发布时间】:2011-08-04 15:36:35
【问题描述】:

我正在使用 Silverlight 控制工具包并尝试将图例放置在图表下方。基于the question here,我正在尝试使用控件模板,但我显然遗漏了一些东西,并且没有显示任何内容来代替图表。任何帮助将不胜感激:

<UserControl x:Class="ClientCenterControls.ReportView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"           
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
    xmlns:project="clr-namespace:ClientCenterControls"
    xmlns:model="clr-namespace:ClientCenterControls.Model"
    mc:Ignorable="d"
    d:DesignHeight="400" d:DesignWidth="600">

    <UserControl.Resources>
        <ControlTemplate x:Key="ChartLayoutBottom" TargetType="toolkit:Chart">
            <Border>
                <StackPanel Orientation="Vertical">
                    <toolkit:Title Grid.Row="0" Content="{TemplateBinding Title}" />
                    <toolkit:Legend x:Name="Legend" Header="{TemplateBinding LegendTitle}" Grid.Row="2" />
                </StackPanel>
            </Border>
        </ControlTemplate>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                <GradientStop Color="Silver" />
                <GradientStop Color="Gray" Offset="0.5"/>
                <GradientStop Color="White" Offset="1"/>
            </LinearGradientBrush>
        </Grid.Background>


        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="350" />
            <ColumnDefinition Width="250" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="25" />
            <RowDefinition />
        </Grid.RowDefinitions>


        <sdk:Label x:Name="headerLabel" Content="Client Center CSA" 
                   HorizontalAlignment="Center" Foreground="#444"
                   Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="0" />

        <Controls:DataGrid x:Name="gridDrivers" ItemsSource="{Binding Drivers}"
            Grid.Row="1" Grid.Column="0">
        </Controls:DataGrid>


        <Controls:DataPager x:Name="dataPager1" Source="{Binding Drivers}"
            Grid.Row="1" Grid.Column="0" PageSize="5" />

        <toolkit:Chart x:Name="chartDrivers" Template="{StaticResource ChartLayoutBottom}"
         Grid.Row="1" Grid.Column="1">
            <toolkit:Chart.Series>
                <toolkit:PieSeries 
                        ItemsSource="{Binding Drivers}"
                        IndependentValueBinding="{Binding DriverIdentifier}" 
                        DependentValueBinding="{Binding ScoreImpact}"
                          />
            </toolkit:Chart.Series>
        </toolkit:Chart>
    </Grid>
</UserControl>

【问题讨论】:

    标签: silverlight xaml silverlight-toolkit


    【解决方案1】:

    从对Chart 的原始Template 的调查来看,您似乎错过了一个名为“ChartArea”的EdgePanel 对象,它是Chart 的一个模板部分。

    尝试使用此模板:

    <ControlTemplate x:Key="SomeKey" TargetType="toolkit:Chart">
        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <toolkit:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}"/>
                <Grid Margin="0,15,0,15" Grid.Row="1">
                    <!--Original definitions-->
                    <!--<Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>-->
                    <!--New definitions for the Legend to be bellow the Chart-->
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <!--Original definition, replaced by Grid.Row="1" on the Legend object-->
                    <!--Grid.Column="1"-->
                    <toolkit:Legend x:Name="Legend" Grid.Row="1" Header="{TemplateBinding LegendTitle}" Style="{TemplateBinding LegendStyle}"/>
                    <System_Windows_Controls_DataVisualization_Charting_Primitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}">
                        <Grid Style="{TemplateBinding PlotAreaStyle}" Canvas.ZIndex="-1"/>
                        <Border BorderBrush="#FF919191" BorderThickness="1" Canvas.ZIndex="10"/>
                    </System_Windows_Controls_DataVisualization_Charting_Primitives:EdgePanel>
                </Grid>
            </Grid>
        </Border>
    </ControlTemplate>
    

    【讨论】:

      猜你喜欢
      • 2019-08-01
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      • 2022-12-01
      • 1970-01-01
      • 2015-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多