Expander in ListBoxItem Width Problem
-
I'm working on this control[^]. The code is in this repository[^]. It has a listbox filled with expanders. I can't seem to get the expanders to size horizontally corrrectly. The expanders should horizontally fill inside the listboxitem. This is what I'm gettting[^] I tried binding the width of the expander to the width of the listboxitem, but it gives some strange results. See this[^] I found some Google hits that say to set the width of the expanders header content. Here's one example[^]. I've tried this and it has the same affect as in my second picture. And, even more strange, when I do try to bind the width, the vertical scrollbar on the right is visible and enabled, but no longer drags to scroll. Mouse wheel scrolling is unafffected Anyone know the right way to do this?
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
I'm working on this control[^]. The code is in this repository[^]. It has a listbox filled with expanders. I can't seem to get the expanders to size horizontally corrrectly. The expanders should horizontally fill inside the listboxitem. This is what I'm gettting[^] I tried binding the width of the expander to the width of the listboxitem, but it gives some strange results. See this[^] I found some Google hits that say to set the width of the expanders header content. Here's one example[^]. I've tried this and it has the same affect as in my second picture. And, even more strange, when I do try to bind the width, the vertical scrollbar on the right is visible and enabled, but no longer drags to scroll. Mouse wheel scrolling is unafffected Anyone know the right way to do this?
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
Remove the
Width
binding and theHorizontalAlignment
on thectrls:NavigationPane
element. Instead, set theHorizontalContentAlignment
property on theListBox
.<Setter Property="MaxHeight" Value="300"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ctrls:NavigationPane}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="\*"/> </Grid.ColumnDefinitions> <Expander Header="{Binding Header, RelativeSource={RelativeSource TemplatedParent}}" Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}}" Margin="{Binding Margin, RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}" BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" IsExpanded="True"> <Grid> <ListBox ItemsSource="{Binding Items, RelativeSource={RelativeSource TemplatedParent}}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="2" BorderBrush="Transparent" BorderThickness="0"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Caption}" </x-turndown>
-
Remove the
Width
binding and theHorizontalAlignment
on thectrls:NavigationPane
element. Instead, set theHorizontalContentAlignment
property on theListBox
.<Setter Property="MaxHeight" Value="300"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ctrls:NavigationPane}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="\*"/> </Grid.ColumnDefinitions> <Expander Header="{Binding Header, RelativeSource={RelativeSource TemplatedParent}}" Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}}" Margin="{Binding Margin, RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}" BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" IsExpanded="True"> <Grid> <ListBox ItemsSource="{Binding Items, RelativeSource={RelativeSource TemplatedParent}}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="2" BorderBrush="Transparent" BorderThickness="0"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Caption}" </x-turndown>
That did it. I spent hours trying to figure that out. It seems in this case all the properties have to be just right. Thanks
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.