Question

I am trying to bind some diagrams to a dictionary of string, int, and I am using a view-viewmodel pattern.

I have bound the dictionary already to a bar-diagram, but now I would like to bind it to the treemap control from the WPF Toolkit. It's not really documented anywhere online, except here for silverlight: http://blogs.msdn.com/marlat/archive/2009/07/10/treemap-control-comes-to-silverlight-toolkit.aspx

Can anyone help me fix the right binding to my control?

<DataVisualization:TreeMap x:Name="treeMapControl">

                            <DataVisualization:TreeMap.Interpolators>

                                <DataVisualization:SolidColorBrushInterpolator TargetName="itemBorder" TargetProperty="Background"

                                       DataRangeBinding="{Binding Source={StaticResource ShellVM},Path=CustodianEmailCount.Value}" From="Blue" To="Magenta" />

                                <DataVisualization:DoubleInterpolator TargetName="textBlk" TargetProperty="FontSize"

                                       DataRangeBinding="{Binding Source={StaticResource ShellVM},Path=CustodianEmailCount.Value}" From="8" To="15" />

                            </DataVisualization:TreeMap.Interpolators>



                            <DataVisualization:TreeMap.ItemDefinition>

                                <DataVisualization:TreeMapItemDefinition ItemsSource="{Binding Source={StaticResource ShellVM},Path=CustodianEmailCount.Key}" ValueBinding="{Binding Source={StaticResource ShellVM},Path=CustodianEmailCount.Value}" ChildItemPadding="1">

                                    <DataTemplate>

                                        <Border x:Name="itemBorder" BorderBrush="Black" BorderThickness="1" ToolTipService.ToolTip="{Binding ToolTip}">

                                            <TextBlock x:Name="textBlk"  Foreground="White" Text="{Binding Source={StaticResource ShellVM},Path=CustodianEmailCount.Key}" VerticalAlignment="Center" Margin="2,2,0,0"

                                   TextWrapping="Wrap" TextAlignment="Center"/>

                                        </Border>

                                    </DataTemplate>

                                </DataVisualization:TreeMapItemDefinition>

                            </DataVisualization:TreeMap.ItemDefinition>

                        </DataVisualization:TreeMap>
Was it helpful?

Solution

The Problem is that you keep calling "Binding Source={StaticResource ShellVM}" on every item which might cause (depend on your implementation). Anyway it's not really the correct way of using it while implementing MVVM. The right way to do it is setting the father's container (of even the complete view if you are implementing MVVM) DataContext which results its leaf to inherates the VM:

DataContext={Binding Source={StaticResource ShellVM}

and then for instance:

Text = {Binding CustodianEmailCount.Key}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top