use*_*016 0 c# mvvm windows-phone
这是我的XAML,在windows手机中,我使用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>
Run Code Online (Sandbox Code Playgroud)
而我的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();
}
}
Run Code Online (Sandbox Code Playgroud)
这里我将viewmodel设置为mainPage,
public MainPage()
{
InitializeComponent();
this.DataContext = App.ViewModel;
}
Run Code Online (Sandbox Code Playgroud)
但我在页面上找不到任何细节!可能是什么原因?
您尚未为列表框的ItemsSource属性指定任何值,
在你的XAML中,
<ListBox Grid.Row="0" ItemsSource="{Binding Employees}"
SelectionMode="Single" SelectedItem="{Binding CurrentSelectedEmployee, Mode=TwoWay}">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
248 次 |
| 最近记录: |