WPF等待绑定完成

时间:2011-06-29 12:09:18

标签: c# wpf xaml binding

我得到了以下XAML:

<ng:Chart Palette="TheTreesPalette">
    <ng:Chart.Diagrams>
        <Diagram Key="PersonnelHoursAWeek" For="{Binding}" Value="BarSeries3D" />
        <Diagram Key="PersonId" For="{Binding}" Value="BarSeries3D" />
    </ng:Chart.Diagrams>
</ng:Chart>

在代码中:

  • 图表是一个简单的ContentControl。
  • Diagrams是Chart
  • 中的集合(和DependencyObject)和DependencyProperty
  • 图是Diagrams中的DependencyObject

当图表添加到图表列表时,我的图表需要更新。通过使用DependencyProperty.Register,我已经注册了“Diagrams”列表,但是它不会等待绑定(因此,当“事件”通过时,For属性(图表)是空的。)

chart.cs:

public static readonly DependencyProperty DiagramsProperty = DependencyProperty.Register("Diagrams", typeof(SkillsNG.Application.Behaviors.DiagramCollection), typeof(Chart), new UIPropertyMetadata(null, FunctionToCall));
private static void FunctionToCall(DependencyObject @this, DependencyPropertyChangedEventArgs e)
{
}

我可以做些什么来获得一个填充的For属性?

顺便说一下,事件“Loaded”仍然没有绑定。

再解释一下: 图表可以有多个条形图/线条,For属性会将数据集提供给一个条形图/线条(在我的示例中称为图表)。关键是它的DataMember。

绑定是对给定视图的模型的绑定。但是Binding可以是“Binding Set1”和“Binding Set2”(我想要显示的行的数据集)。

绑定100%正确,我的图表将在我等待一秒钟将其全部绑定时显示。所以我希望那个eighter Diagram通知Chart它已被更改,或者Chart可以添加一个事件(Diagram.ForProperty.AddOwner就像构造一样)。

1 个答案:

答案 0 :(得分:0)

不确定您的Chart DataContext设置为什么(这是子元素上的{Binding}会给你的)但是Diagrams集合及其成员不是元素因此不会成为Wpf逻辑树的一部分,因此不会继承父Chart DataContext。当你在debug中运行它时,我希望在输出窗口中看到Binding错误。

我认为你基本上遇到了与这个问题相同的问题:How to bind the same collection of values into all ComboBoxes in a DataGridComboBox?,它为在Wpf逻辑树中弥合这一差距提供了解决方案。