4

I'm facing an irritating problem with WPF GroupBox, hope someone can help me out. Basically the problem is this: I have a listview inside a GroupBox, but no matter what I do I can't seem to be able to make it fill the GroupBox.

Here is the basic code:

<GroupBox Grid.Row="2" Header="Field" Visibility="{Binding ElementName=radioUnbound, Path=IsChecked, Converter={StaticResource bool2vis}}" Margin="0" VerticalContentAlignment="Stretch">
        <ListView ItemsSource="{Binding ElementName=nnf1, Path=UnboundFields}" x:Name="listUnbound" SelectionChanged="listSelectionChanged" VerticalAlignment="Stretch" >
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding name}" Margin="2"/>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </GroupBox>

I tried encasing the list inside Grids, StackPanels, DockPanel, etc... but no matter what I try I always invariably end up with this:

enter image description here

Master_T
  • 7,232
  • 11
  • 72
  • 144
  • Have your tried to place a grid inside your groupbox? How is Grid.Row=2 is defined in your main grid, Auto or * ? – Dummy01 Jun 27 '11 at 08:48
  • @Dummy01: yep, read what I've written between the code and the image... I tried every container I could think of, but no luck :( Row 2 is "*", in fact the groupbox itself stretches correctly, it's contents however do not... – Master_T Jun 27 '11 at 08:51
  • Your code works perfectly on my machine. Did you maybe set a default style for ListView somewhere where you specified a height? – Jens Jun 27 '11 at 08:58
  • I did a search on the entire solution, there's no style targeting either ListView or GroupBox... – Master_T Jun 27 '11 at 09:16

1 Answers1

7

I tried your code in XamlPad it works as you would expect it. Make sure you don't have global styles that set your ListView or GroupBox appearance.

You can clear global styles by putting this in the resources section of the GroupBox's parent control:

<Style TargetType="GroupBox" />
<Style TargetType="ListView" />
thumbmunkeys
  • 20,606
  • 8
  • 62
  • 110
  • I don't use global syles. In the visual studio designer it seems to work correctly as well, but when compiled and running the result is the one shown in that window. – Master_T Jun 27 '11 at 08:58
  • If it looks ok in the designer then this is a strong indication for some style that comes from somewhere outside of the xaml file – thumbmunkeys Jun 27 '11 at 09:01
  • @x0r: I tried putting those styles in the groupbox's parent (the Grid in this case) but to no avail, still the same... – Master_T Jun 27 '11 at 09:07
  • @Master_T: can you post the whole form? – thumbmunkeys Jun 27 '11 at 11:26
  • @x0r: I solved, and I'm a fu**ing idiot -_- I had forgotten there were actually 2 listviews on the 2nd line of the grid, that got switched depending on which of the two radiobuttons you see in the screenshot is checked. I ws editing the one for the "Unbound" button, not the other one (which was the one I was seeing when launching the form to test). Very sorry to have wasted your time guys... I'll one-up your answer nontheless for your support and quick response. – Master_T Jun 27 '11 at 12:05
  • @Master_T: thanks for marking as answered. don't worry, such errors can happen to the best :) – thumbmunkeys Jul 13 '11 at 13:47
  • Though it might work this way, this answer is no use to anybody using some Style. It would be way better to know which properties cause this behavior instead of just nuking them all.... – D4rth B4n3 Feb 14 '17 at 12:03