WPF 自定义雷达图开发实例教程

2019-12-30 13:54:41刘景俊

3、定义数据组标题显示列表

wdf,雷达图

前台:


<UserControl x:Class="WpfApplication2.RadarChartTitleList"
  xmlns="http://www.easck.com/winfx/2006/xaml/presentation"
  xmlns:x="http://www.easck.com/winfx/2006/xaml"
  xmlns:mc="http://www.easck.com/markup-compatibility/2006" 
  xmlns:d="http://www.easck.com/expression/blend/2008" 
  mc:Ignorable="d" 
  d:DesignHeight="300" d:DesignWidth="300" Loaded="RadarChartTitleList_OnLoaded">
 <UserControl.Resources>
 <Style x:Key="ItemContainer" TargetType="{x:Type ListBoxItem}">
  <Setter Property="Template">
  <Setter.Value>
   <ControlTemplate TargetType="{x:Type ListBoxItem}">
   <Border x:Name="IconBorder" Background="Transparent" CornerRadius="4" BorderThickness="0">
    <ContentPresenter />
   </Border>
   <ControlTemplate.Triggers>
    <Trigger Property="IsSelected" Value="true">
    <Setter TargetName="IconBorder" Property="BitmapEffect">
     <Setter.Value>
     <OuterGlowBitmapEffect GlowColor="Transparent" GlowSize="5" />
     </Setter.Value>
    </Setter>
    </Trigger>
   </ControlTemplate.Triggers>
   </ControlTemplate>
  </Setter.Value>
  </Setter>
 </Style>
 </UserControl.Resources>
 <Grid>
 <ListBox x:Name="MyListBox" ItemsSource="{Binding}" ItemContainerStyle="{StaticResource ItemContainer}" FocusVisualStyle="{x:Null}">
  <ListBox.Template>
  <ControlTemplate>
   <StackPanel Background="Transparent" IsItemsHost="True"></StackPanel>
  </ControlTemplate>
  </ListBox.Template>
  <ListBox.ItemTemplate>
  <DataTemplate>
   <Grid HorizontalAlignment="Left" VerticalAlignment="Center" Background="Transparent">
   <Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto"></ColumnDefinition>
    <ColumnDefinition Width="*"></ColumnDefinition>
   </Grid.ColumnDefinitions>
   <Grid HorizontalAlignment="Center" Margin="10,0" Background="Transparent">
    <Ellipse Fill="{Binding Color}" Height="6" Width="6" HorizontalAlignment="Right" VerticalAlignment="Center"></Ellipse>
    <Canvas VerticalAlignment="Center" HorizontalAlignment="Center">
    <Path Fill="{Binding Color}" Height="5" StrokeThickness="1" Stroke="{Binding Color}" VerticalAlignment="Center" Data="M-10,0 L10,0"></Path>
    </Canvas>
   </Grid>
   <TextBlock Grid.Column="1" Text="{Binding Name}" Foreground="White" Background="Transparent"></TextBlock>
   </Grid>
  </DataTemplate>
  </ListBox.ItemTemplate>
 </ListBox>
 </Grid>
</UserControl>