gpt4 book ai didi

xaml - ListView 选定项绑定(bind)不起作用

转载 作者:行者123 更新时间:2023-12-03 10:14:04 24 4
gpt4 key购买 nike

我在 uwp 中有一个 listview ,以及一个在其中声明 Pataient_List 和 selected_pa​​tient 的 View 模型。我的 listview 显示 itemsource 但我不知道为什么我的 listview 不显示所选项目。

 <ListView   ItemsSource="{Binding pataient_List}"
SelectedItem="{Binding selected_patient, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding name_to_show_menu, Mode=TwoWay}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

View 模型是
public class patient_view_model : notify_property_changed_base
{
public patient_view_model(patient patient_param)
{
pataient_List = new ObservableCollection<patient>();
load_patient(); // this function put patients in pataient_List
selected_patient = patient_param;
}

public patient selected_patient
{
get { return _selected_patient; }
set
{
if (_selected_patient != value)
{
_selected_patient = value;
RasiePropertyChanged();
}
}
}
public ObservableCollection<patient> pataient_List { set; get; }

最佳答案

一个原因可能是所选项目必须是 pataient_List 中的对象之一。 .

另一个原因可能是因为您正在设置 selected_patient在 View 模型的构造函数中,这肯定是在将 View 模型绑定(bind)到 View 之前。那么,为什么不尝试设置 selected_patient将 View 模型绑定(bind)到 View 之后。

关于xaml - ListView 选定项绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38612481/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com