void InitLegend()
{
// 凡例を作成します
legend.Items.Clear();
ColorValues cvals = (ColorValues)countries.Converter;
int cnt = cvals.Count;
double sz = 20;
for (int i = 0; i < cnt - 1; i++)
{
ColorValue cv = cvals[i];
ListBoxItem lbi = new ListBoxItem()
{
Height = sz,
Margin = new Thickness(0),
Padding = new Thickness(0)
};
StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal };
LinearGradientBrush lgb = new LinearGradientBrush() { StartPoint = new Point(0, 0), EndPoint = new Point(0, 1) };
lgb.GradientStops.Add(new GradientStop() { Color = cv.Color, Offset = 0 });
lgb.GradientStops.Add(new GradientStop() { Color = cvals[i + 1].Color, Offset = 1 });
sp.Children.Add(new Rectangle()
{
Width = sz,
Height = sz,
Fill = lgb,
Stroke = new SolidColorBrush(Colors.LightGray),
StrokeThickness = 0.5,
RenderTransform = new TranslateTransform() { Y = 0.5 * sz }
});
sp.Children.Add(new TextBlock()
{
Height = sz,
Text = cv.Value.ToString(),
VerticalAlignment = VerticalAlignment.Center,
});
lbi.Content = sp;
legend.Items.Add(lbi);
}
legend.Items.Add(new ListBoxItem() { Height = sz });
}