gpt4 book ai didi

c# - 为什么我的ListBox不显示任何数据?

转载 作者:行者123 更新时间:2023-12-03 10:53:28 25 4
gpt4 key购买 nike

这是我的XAML,在Windows Phone中,我正在使用MVVM设置数据到页面,但是我在列表框中找不到任何数据。

<ListBox Grid.Row="0"  SelectionMode="Single" SelectedItem="{Binding CurrentSelectedEmployee, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding FirstName}"></TextBlock>
<TextBlock Width="5"></TextBlock>
<TextBlock Text="{Binding LastName}"></TextBlock>
</StackPanel>
<TextBlock Text="{Binding Description}" TextWrapping="Wrap"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

还有我的ViewModel
 public MainViewModel()
{
Employees = new ObservableCollection<Model.Employee>();
}

public bool IsLoaded { get; set; }

public void LoadData()
{
Employees = CompanyDataPhone.Service.EmployeeService.GetEmployees();
IsLoaded = true;
}
// public ObservableCollection<Model.Employee> Employees { get; set; }

public ObservableCollection<CompanyDataPhone.Model.Employee> _employees;

public ObservableCollection<CompanyDataPhone.Model.Employee> Employees
{
get {

return _employees;
}
set
{

_employees = value;
OnpropertyChanged();
}
}

在这里,我将viewmodel设置为mainPage,
public MainPage()
{
InitializeComponent();

this.DataContext = App.ViewModel;

}

但我在Page!上找不到任何详细信息,这可能是什么原因?

最佳答案

您尚未为列表框的ItemsSource属性分配任何值,

在您的XAML中,

<ListBox Grid.Row="0" ItemsSource="{Binding Employees}" 
SelectionMode="Single" SelectedItem="{Binding CurrentSelectedEmployee, Mode=TwoWay}">

关于c# - 为什么我的ListBox不显示任何数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22463195/

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