【问题标题】:Windows Phone BindingWindows Phone 绑定
【发布时间】:2013-02-12 20:57:25
【问题描述】:

在我的 RoomView.xaml 中有:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <ListBox ItemsSource="{Binding myStrings, Mode=TwoWay}"></ListBox>
</Grid>

在我的构造函数中我正在做:

 var myStrings = new List<string>{"Usmaan","Carl","Andy","Saul"};
 DataContext = myStrings;

当我加载应用程序时,页面上没有任何内容被吐出。

谁能看出我哪里出了大错?

【问题讨论】:

    标签: binding windows-phone


    【解决方案1】:

    你的页面的DataContext已经设置为List对象,所以你只需要像这样设置绑定:

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <ListBox ItemsSource="{Binding, Mode=TwoWay}"></ListBox>
    </Grid>
    

    或者,您可以创建一个具有MyStrings 属性的对象并将其用作页面的DataContext。然后,您可以像绑定{Binding myStrings, Mode=TwoWay} 一样绑定ListBox,同时还可以将其他控件绑定到该对象的其他属性(这是 ViewModel 的原理)。

    【讨论】:

    猜你喜欢
    • 2014-01-15
    • 2013-12-30
    • 1970-01-01
    • 2015-01-18
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 2013-05-24
    相关资源
    最近更新 更多