截图:显示属性
选择项目从上面的ListView显示了它们在下面的数据网格特性。
XAML:
<Window x:Class="EmployeeSystem.Run_with_XML"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:EmployeeSystem"
mc:Ignorable="d"
Title="Run with XML" Height="398.299" Width="305.91" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
<Grid Height="325" VerticalAlignment="Top">
<StackPanel>
<ListView Height="100" DisplayMemberPath="Name" ItemsSource="{Binding employees}" SelectedItem="{Binding SelectedEmployee}"/>
<DataGrid Height="100" ItemsSource="{Binding EmployeesView}"/>
</StackPanel>
<Button x:Name="button" Content="Create New" Height="24" Margin="112,0,111,-30" VerticalAlignment="Bottom"/>
</Grid>
</Window>
VeiwModel:
class ViewModel
{
private Employee selectedEmployee;
public ICollectionView EmployeesView { get; set; }
EmployeeManagerXML emx = new EmployeeManagerXML();
public ViewModel()
{
EmployeesView = new ListCollectionView(emx.getEmployeesList()) //this is an ObservableCollection
{
Filter = obj =>
{
var Employee = (Employee)obj;
return SelectedEmployee != null && Employee.Name == SelectedEmployee.Name;
}
};
}
public Employee SelectedEmployee
{
get { return selectedEmployee; }
set
{
if (selectedEmployee != value)
{
selectedEmployee = value;
EmployeesView.Refresh();
}
}
}
}
我一直拼命,现在实现这个几天...我搜索谷歌几个小时......想尽一切在stackoverflow上的相关页面...这篇文章是我最后的希望...有人请告诉我哪里出错了。我已经知道这是一个重复.. This情景是完全一样的,我做了一切完全一样的答案说...仍然是我的工作。
在输出窗口中是否有任何绑定错误? – Pravin
在输出窗口中没有错误 –
您的ListView的ItemSource绑定到“employees”属性,您的ViewModel中的属性在哪里? – Pravin