从 wpf 工具包将静态资源字典数据绑定到树形图

发布于 2024-08-28 23:39:55 字数 2428 浏览 7 评论 0 原文

我正在尝试将一些图表绑定到字符串、int 的字典,并且我正在使用视图-视图模型模式。

我已经将字典绑定到条形图,但现在我想将其绑定到 WPF 工具包中的树形图控件。除了 silverlight 之外,网上的任何地方都没有真正记录它: http://blogs.msdn.com/marlat/archive/2009/07/10/treemap-control-comes-to-silverlight-toolkit.aspx

任何人都可以帮我修复正确绑定到我的控件?

<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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回旧景 2024-09-04 23:39:55

问题是您不断对可能导致的每个项目调用“Binding Source={StaticResource ShellVM}”(取决于您的实现)。无论如何,这并不是实现 MVVM 时使用它的正确方法。
正确的方法是设置父容器(如果您正在实现 MVVM,甚至是完整视图)DataContext,这会导致其叶子继承 VM:

DataContext={Binding Source={StaticResource ShellVM}

然后例如:

Text = {Binding CustodianEmailCount.Key}

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}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文