私はtelerikを使ってグラフを作成します。今私はそれに伝説を追加するつもりです。 例はhereです。MVVMを使用してMarkerFillとTitleのバインドを行う:LegendItem
XAMLは次のとおりです。
<telerik:RadLegend HorizontalAlignment="Center" UseLayoutRounding="True">
<telerik:RadLegend.ItemTemplate>
<DataTemplate>
<Border Background="{Binding MarkerFill}" BorderThickness="1" BorderBrush="{Binding MarkerStroke}">
<Grid>
<TextBlock Text="{Binding Title}" Foreground="White" Margin="15 0 0 0" />
<Path Width="12"
Height="12"
Fill="White"
HorizontalAlignment="Left">
<Path.Data>
<Binding Path="ActualMarkerGeometry"
RelativeSource="{RelativeSource AncestorType=telerik:LegendItemControl}">
</Binding>
</Path.Data>
</Path>
</Grid>
</Border>
</DataTemplate>
</telerik:RadLegend.ItemTemplate>
<telerik:RadLegend.Items>
<telerik:LegendItemCollection>
<telerik:LegendItem MarkerFill="#FF55AA33" MarkerStroke="Black" Title="Legend item 1" />
<telerik:LegendItem MarkerFill="#FFCC3399" MarkerStroke="Black" Title="Legend item 2" />
<telerik:LegendItem MarkerFill="#FF5511BB" MarkerStroke="Black" Title="Legend item 3" />
</telerik:LegendItemCollection>
</telerik:RadLegend.Items>
それがハードコーディングされているが。私はそれをMVVMと結びつけたい。バインドする方法を教えてくださいMarkerFill
とMarkerStroke
。私はそれが文字列のプロパティだとは思わない。
ViewModelのどのタイプですか?
EDIT:
ObservableCollection<ChartData> data = new ObservableCollection<ChartData>();
data.Add(new ChartData() { Category = "Red", Title = "one" });
data.Add(new ChartData() { Category = "Green", Title = "two" });
data.Add(new ChartData() { Category = "Blue", Title = "three" });
data.Add(new ChartData() { Category = "Aqua", Title = "four" });
MarkerFillとMarkerStrokeは、ブラシのプロパティです。実行時に値を動的に変更できるようにしようとしていますか?あるいは、あなたのマークアップで16進値をハードコーディングしないでください。 – Eric
色はビューモデルからのものです。私は、それらをハードディスクに16進数の値をバインドしてバインドしたい。 EDITを参照してください。 – Bigeyes
LegendItemはDependencyObjectではないため、そのプロパティにバインドすることはできません。既にItemTemplateを定義しているので、テンプレート自体の色をバインドしようとしましたか?あなたのビューモデルで定義された色を持つことができ、カスタムコンバータを使用して色をBrushに変換できます。 – Eric