Reputation: 1740
I have a Listbox
of expander items and want them to fill the whole horizontal space available.
Here is a little example
<Window x:Class="ExpanderTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListBox>
<ListBoxItem>
<Expander Background="Tan"
HorizontalAlignment="Left" Header="My Expander"
ExpandDirection="Down" IsExpanded="True">
<TextBlock TextWrapping="Wrap">
Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua
</TextBlock>
</Expander>
</ListBoxItem>
</ListBox>
</Grid>
If I set Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBox}}, Path=ActualWidth}"
on the expander
, it behaves almost as I want it to, except that the expander is a little bit too wide.
Is there a way in xaml to tell the ListBoxItem
or the Expander
to fill all horizontal space available?
(if the width gets smaller, the hight should get larger accordingly to display the whole content)
Upvotes: 0
Views: 2409
Reputation: 1740
ok, I found the solution, just add
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
to the ListBox.
Upvotes: 3