Reputation: 43
I have a listbox which items are built horizontally.
Also i have a DataGrid whose Columns are built dynamically.
Each ListBoxItem is coresponding to a DataGrid Column
I want to sync between the DataGrid Column and the right ListBoxItem, so each ListBoxItem will be parallel to a column. Also when resizing the column , it will change the size of the ListBoxItem. How can i do it?
Upvotes: 0
Views: 848
Reputation: 717
You can bind item width with to the datagrid column actualwidth
<StackPanel Grid.Column="1" Orientation="Vertical">
<DataGrid Grid.IsSharedSizeScope="True">
<DataGrid.Columns>
<DataGridTextColumn Header="Some col 1" x:Name="first" />
<DataGridTextColumn Header="Some col 2" x:Name="second" />
<DataGridTextColumn Header="Some col 3" />
</DataGrid.Columns>
</DataGrid>
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel IsItemsHost="True" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<Button Content="button 1" Width="{Binding Path=ActualWidth, ElementName=first}"></Button>
<Button Content="button 2" Width="{Binding Path=ActualWidth, ElementName=second}"></Button>
</ListBox>
</StackPanel>
If you create them dynamically, set binding in code.
Upvotes: 2