KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to create an ItemsControl that uses a grid as its ItemsPanel in such a way that it has two columns, where the first columns width is the width of the widest item in that column, and has as may rows needed to display all the items Basically, I want the following, but somehow within an ItemsControl so that I can bind to a collection of objects: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="auto"/> <RowDefinition Height="auto"/> <RowDefinition Height="auto"/> </Grid.RowDefinitions> <Label Content="{Binding Items[0].Header}"/> <TextBox Text="{Binding Items[0].Content}" Grid.Column="1"/> <Label Content="{Binding Items[1].Header}" Grid.Row="1"/> <TextBox Text="{Binding Items[1].Content}" Grid.Row="1" Grid.Column="1"/> <Label Content="{Binding Items[2].Header}" Grid.Row="2"/> <TextBox Text="{Binding Items[2].Content}" Grid.Row="2" Grid.Column="1"/> </Grid> Edit : Rachels answer worked great, here is a working example. (I moved the Grid.IsSharedSizeScope="True" to the ItemsPanel, not sure if Rachel meant to put it in the ItemTemplate (which didn't work)) namespace WpfApplication23 { public partial class Window1 : Window { public List<Item> Items { get; set; } public Window1() { Items = new List<Item>() { new Item(){ Header="Item0", Content="someVal" }, new Item(){ Header="Item1", Content="someVal" }, new Item(){ Header="Item267676", Content="someVal" }, new Ite
Tags (comma-separated)
Save Edits
Cancel