c# - 如何在更新 WPF(MVVM)中的值时在组合框中显示正确的数据值?
问题描述
我有 2 张桌子
Scan Table have [ScanId],[Name],[Mode]
Tags Table have [Name],[Description],[ScanRefId]FOREIGN KEY([ScanRefId])
在插入数据时它工作正常。但是在更新时, 我想在组合框中显示 selectedvalue/storedvalue(外键)。但组合框始终显示绑定数据的第一个值。 我错过了什么?
My XAML code is:
<ComboBox
x:Name="cbscanservice"
Style="{StaticResource MaterialDesignFloatingHintComboBox}"
ItemsSource="{Binding Scanvalues}"
SelectedValue="{Binding Scan}"
SelectedValuePath="Name"
DisplayMemberPath="Name"
FontSize="14"
Grid.Row="2"
IsEditable="False"
materialDesign:HintAssist.Hint="Scan Service"
Height="40"
Margin="0,0,0,20"
VerticalAlignment="Bottom">
</ComboBox>
///UpdateviewModel----code
public IEnumerable<DB.model.Scan> Scanvalues
{
get { return Getscans(); }
}
private IList<DB.model.Scan> Getscans()
{
_scann = new List<DB.model.Scan>();
foreach (var scanname in scanService.GetAll())
{
_scann.Add(scanname);
}
return _scann;
}
public DB.model.Scan Scan
{
get { return _scan; }
set
{
_scan = value;
OnPropertyChanged("Scan");
}
}
解决方案
推荐阅读
- 3dsmax - 按下 UI 按钮会扭曲模型
- cefsharp - Cefsharp 以画中画模式播放视频
- mysql - SQLSTATE[HY000] [2002] 在 laravel 和 docker 设置上连接被拒绝
- ios - 当我看到“将本地更改重新设置为上游更改”消息时,如何覆盖 XCode 存储库中的所有本地更改?
- javascript - 我想要日期范围选择器以及“DD/MM/YYYY”格式的输出数据
- scala - 使用 HBase Sink 的 Spark 结构化流
- mongodb - 如果输入数组的元素至少匹配一个,则获取数组的大小
- javascript - 当我在模板文字中使用 .map 时,为什么我的输出中有逗号?
- python - 按级别提取嵌套列表中的字符串
- python - 运行机器人文件的命令,我也可以在其中指定 python 版本