【发布时间】:2016-04-13 10:44:36
【问题描述】:
我有这个 XAML...
<ListView ItemsSource="{Binding AllRoundIDs}" Height="96"
SelectedItem="{Binding AllRoundsSelectedItem, Mode=TwoWay}"
SelectionMode="Single"
>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Key}" FontSize="30" Foreground="White" Padding="0,0,0,1" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我的 ViewModel 中的这段代码...
private ObservableCollection<KeyValuePairs> _AllRoundIDs;
public ObservableCollection<KeyValuePairs> AllRoundIDs
{
get { return _AllRoundIDs; }
private set { Set(ref _AllRoundIDs, value); }
}
private KeyValuePairs _AllRoundsSelectedItem;
public KeyValuePairs AllRoundsSelectedItem
{
get { return _AllRoundsSelectedItem; }
private set { Set(ref _AllRoundsSelectedItem, value); }
}
KeyValuePairs 类看起来像这样...
public class KeyValuePairs
{
public string Key { get; set; }
public string Value { get; set; }
}
当我运行我的应用程序时,我会按预期在我的 ListView 中获得项目。所以我知道数据绑定正在工作。
当我点击一个项目时,我没有得到任何生命。与 AllRoundsSelectedItem 的绑定不会触发。此代码在 WPF 应用程序中运行良好,但在 UWP 中我一无所获。我错过了什么?
提前致谢。
【问题讨论】: