How do I make a WPF data template fill the entire width of the listbox?

后端 未结 8 1366
别跟我提以往
别跟我提以往 2020-12-04 16:23

I have a ListBox DataTemplate in WPF. I want one item to be tight against the left side of the ListBox and another item to be tight ag

8条回答
  •  一个人的身影
    2020-12-04 16:57

    The Grid should by default take up the whole width of the ListBox because the default ItemsPanel for it is a VirtualizingStackPanel. I'm assuming that you have not changed ListBox.ItemsPanel.

    Perhaps if you got rid of the middle ColumnDefinition (the others are default "*"), and put HorizontalAlignment="Left" on your WrapPanel and HorizontalAlignment="Right" on the ListBox for phone numbers. You may have to alter that ListBox a bit to get the phone numbers even more right-aligned, such as creating a DataTemplate for them.

提交回复
热议问题