Ral*_*alt 0 c# data-binding silverlight
我有一个 在我的表格上ComboBox
绑定的DependencyProperty
.我可以通过Button
点击向这个属性添加项目,它会将它们添加到ComboBox
.但是,一旦我放下ComboBox
绑定断裂.我仍然可以向该属性添加项目,但我ComboBox
永远不会更新以显示它们.
例如
Button
三次ComboBox
下来-这将有三个项目Button
另外三次ComboBox
下来-它仍然将只有三个项目再次启动应用程序并:
Button
六次ComboBox
下来-这将有六个项目<Grid x:Name="LayoutRoot"
Background="White">
<ComboBox Name="combTest"
ItemsSource="{Binding Users}"
Width="50"
Height="50"
HorizontalAlignment="Left" />
<Button Click="ButtonBase_OnClick"
Width="50"
Height="50"
HorizontalAlignment="Right" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
public MainPage()
{
InitializeComponent();
this.DataContext = this;
}
public static readonly DependencyProperty UsersProperty = DependencyProperty.Register(
"Users", typeof (List<string>), typeof (MainPage), new PropertyMetadata(new List<string>()));
public List<string> Users
{
get { return (List<string>) GetValue(UsersProperty); }
set { SetValue(UsersProperty, value); }
}
private int i = 0;
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
Users.Add("User " + i++);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
28 次 |
最近记录: |