проблемс в wpf с listview
Мне нужно добавить из list в listview, но не могу, вылетает ошибка Перед использованием свойства ItemsSource семейство Items должно быть пустым
вот код xaml
<Window x:Class="FamCalculator.MainWindow"
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:FamCalculator"
mc:Ignorable="d"
Title="MainWindow" Height="496" Width="347">
<Grid Margin="0,0,0,-6">
<Grid.RowDefinitions>
<RowDefinition Height="176*"/>
<RowDefinition Height="370*"/>
<RowDefinition Height="109*"/>
</Grid.RowDefinitions>
<ListView x:Name="AllList" Margin="73,42,72,193" BorderBrush="Black" Background="White" Grid.RowSpan="2" Initialized="AllList_Initialized">
<ListView.View>
<GridView>
<GridViewColumn Width="188" DisplayMemberBinding="{Binding Name}">Имя</GridViewColumn>
</GridView>
</ListView.View>
<ListBox Height="100" Width="100"/>
</ListView>
</Grid>
</Window>
мой код
public ObservableCollection<string> Fam { get; set; }
public MainWindow()
{
InitializeComponent();
Fam = new ObservableCollection<string>();
Fam.Add("John Doe");
AllList.ItemsSource = Fam;
}
пробовал так, о увы
List<User> items = new List<User>();
items.Add(new User() { Name = "John Doe"});
items.Add(new User() { Name = "Jane Doe"});
items.Add(new User() { Name = "Sammy Doe"});
AllList.ItemsSource = items;
}
public class User
{
public string Name { get; set; }
}