我有一个名为UserControl
的{{1}},它有一个名为MultiChartControl
的依赖项属性。
MultiChartInputDetails
但是以下回调方法甚至不会被触发一次:
public ChartsData MultiChartInputDetails
{
get { return (ChartsData)GetValue(MultiChartInputDetailsProperty); }
set { SetValue(MultiChartInputDetailsProperty, value); }
}
public static readonly DependencyProperty MultiChartInputDetailsProperty =
DependencyProperty.Register("MultiChartInputDetails", typeof(ChartsData), typeof(MultiChartControl), new UIPropertyMetadata(new PropertyChangedCallback(MultiChartInputDetailsChanged)));
主要主控:
private static void MultiChartInputDetailsChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
{
MultiChartControl chart = d as MultiChartControl;
if (chart != null)
{
if (chart.ChartGrid.Children != null)
chart.ChartGrid.Children.Clear();
chart.InitilizeData();
}
MessageBox.Show("MultiChartInputDetailsChanged fired");
}
答案 0 :(得分:1)
这是因为DependencyProperty未设置为双向绑定。这样做如下:
DependencyProperty.Register("MultiChartInputDetails",
typeof(ChartsData),
typeof(MultiChartControl),
new FrameworkPropertyMetadat(default(ChartsData),
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
MultiChartInputDetailsChanged)
进一步检查是否存在绑定错误。如果您不想提供一个依赖属性,默认情况下执行双向绑定,那么您可以按如下方式编写bindinga:
<multicharting:MultiChartControl x:Uid="multicharting:MultiChartControl_1"
MultiChartInputDetails="{Binding Path=MultiChartsInputDetails,
Mode=TwoWay,
ElementName=Chart,
Converter={StaticResource DebugConverter}}"/>