【发布时间】:2011-08-10 20:21:30
【问题描述】:
我有一个正确填充的 ListBox (lstBxsources),并且可以正常工作。
<ListBox Name="lstBxSources" ItemsSource="{Binding}" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" ToolTipService.ToolTip="{Binding Path=Description}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我也有一个 UserControl(MyUserControl)。
<MainControl:MyControl x:Name="MyUserControl" Grid.Row="1"/>
MyUserControl 上有名为“CurrentSourceProperty”的依赖属性
public SourceInfo CurrentSource
{
get { return (SourceInfo)GetValue(CurrentSourceProperty); }
set { SetValue(CurrentSourceProperty, value); }
}
public static readonly DependencyProperty CurrentSourceProperty =
DependencyProperty.Register("CurrentSource", typeof(SourceInfo), typeof(MyControl), new PropertyMetadata(null));
我已将 CurrentSource 数据绑定到 lstBxSources 的 SelectedItem,如下所示:
MyUserControl.SetBinding(MyControl.CurrentSourceProperty, new Binding() { Source = lstBxSources.SelectedItem});
这最初有效,但不会在 SelectedItem 更改时更新。
知道为什么它不会为我更新吗?
【问题讨论】:
标签: c# data-binding silverlight-4.0 listbox