项目中用到使用wpf创建多个图图例,通过前端添加控件需制作多个,于是自己写了个两个通用的图例,本例为分段式图例,即一个区间赋一个颜色,渐变色图例见wpf自定义创建图例2(渐变式)
wpf窗体设置样式代码:
<Window x:Class="wpfTest.ColorLegend"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ColorLegend" Height="326" Width="168" Opacity="0.8"
AllowsTransparency="True" Topmost="True" WindowStyle="None" Background="{x:Null}"
AllowDrop="True" MouseLeftButtonDown="DragWindow" Closed="Window_Closed">
<Window.Resources>
<Style x:Key="lab_Style" TargetType="Label">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="HorizontalAlignment" Value="Left"></Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="Height" Value="25"></Setter>
<Setter Property="Width" Value="70"></Setter>
</Style>
<Style x:Key="title_Style" TargetType="Label">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="FontWeight" Value="Bold"></Setter>
<Setter Property="FontSize" Value="12"></Setter>
<Setter Property="HorizontalAlignment" Valu