Допустим, у меня есть следующее представление списка в xaml:
<ListView Name="myListView" DataContext="{Binding MyProperty}" ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True">
<ListView.Resources>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView >
<GridViewColumn Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding SomeProperty}" TextAlignment="Center"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
как мне создать такой же список с помощью C #?
это то, что я разработал:
ListView myListView = new ListView();
// set bindings
myListView.IsSynchronizedWithCurrentItem = true;
Binding b = new Binding("MyProperty")
{
Source = this
};
myListView.SetBinding(ListView.ItemsSourceProperty, b);
myListView.Resources.Add(; // dont know how to add those resource;
GridView g = new GridView();
GridViewColumn gc = new GridViewColumn();
DataTemplate dt = new DataTemplate(new TextBlock()); // I think this is wrong
g.Columns.Add(gc); // add gridview column
gc.CellTemplate = dt;
myListView.View = g;