Question

I have a dock panel to the left of my screen which contains a listbox. The listbox is populated with custom items, defined in another class. To the right of my listbox i have a gridsplitter.

When i click and drag my gridsplitter, the listbox gets resized as expected, howvever the items inside do not.

I would like the items inside to resize accordingly so i can use textrimming when the control would be cut off.

I currently have:

        <Grid.ColumnDefinitions>
        <ColumnDefinition Width="150" MaxWidth="500" MinWidth="100"/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <toolkit:DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,9,0">
        <Button toolkit:DockPanel.Dock="Top" Height="30" Content="Create" Visibility="{Binding Path=IsVisible, Mode=TwoWay}" Command="{Binding Path=Create, Mode=TwoWay}" />
        <ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto"  HorizontalScrollBarVisibility="Hidden">
            <ListBox HorizontalAlignment="Stretch" ItemContainerStyle="{StaticResource ItemContainerStyle}" ItemsSource="{Binding Path=ViewModel, Mode=TwoWay}" SelectedItem="{Binding Path=Selected, Mode=TwoWay}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
                                <ContentControl HorizontalAlignment="Stretch">
                                <myNamespace:MycustomControl HorizontalAlignment="Stretch" DataContext="{Binding}" Height="40"/>
                                </ContentControl>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </ScrollViewer>
    </toolkit:DockPanel>
    <sdk:GridSplitter Width="10" HorizontalAlignment="Right" Grid.Row="1" Style="{StaticResource VerticalGridSplitterStyle}" />

Also within my custom item class, everything is defined HorizontalAlignment = Stretch and has no fixed width set.

Edit: Also i have tried binding my custom item's width to my listbox width with no luck.

Était-ce utile?

La solution

It turned out that the horizontal scroll bar was causing the issue (even though it wasn't visible)

ScrollViewer.HorizontalScrollBarVisibility="Disabled"

Solved my issue

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top