【发布时间】:2018-03-23 11:17:39
【问题描述】:
我有一个组合框,我正在将 XAML 中的组合框与 viewmodel 字典值绑定。
第一次加载页面时,我尝试从服务器下载字典值并将其设置为字典视图模型变量。
但是组合框看起来是空的,我不明白为什么会发生这种情况,因为 View Model 变量已经更新,这应该会触发组合框的重新加载,但这并没有发生..
仅供参考: 如果我硬编码字典而不是从服务器下载它,我看不到这个问题 当我第二次加载页面时,我没有看到这个问题
更新
XAML
<ComboBox x:Name=“testBox” Margin=“0,0,0,0” PlaceholderText="{StaticResource testText}” ItemsSource="{Binding TestDictionary.Values}” SelectedValue="{Binding DictionaryValue, Mode=TwoWay}" IsEnabled="{Binding IsItLoading, Converter={StaticResource InverseBooleanConverter}}"/>
查看模型
private Dictionary<string, string> testDictionary;
public Dictionary<string, string> TestDictionary
{
get
{
if (this.testDictionary == null)
{
this.testDictionary = new Dictionary<string, string>();
}
return this.testDictionary;
}
set
{
this.Set(() => this.TestDictionary, ref this.testDictionary, value);
}
}
【问题讨论】:
-
您能否发布您的
ViewModel和XAML您如何将数据分配给Combobox? -
@AVK - 我已经更新了有问题的代码示例
标签: xaml combobox mvvm-light uwp-xaml xamarin.uwp