none
Scrollviewer for nestedGrid dynamic height from parent grid or window RRS feed

  • Question

  • Hi,

    i just want to use a scrollviewer in a nested grid. This scrollviewer should use a dynamic height to fill the window till bottom. What should i bind to the height property of the scrollviewer to get the right values dynamically?

    My code comes here:

       <Grid Name="Main" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>

            </Grid.RowDefinitions>
            <Menu Grid.Column="6" Grid.Row="0" Height="28" Width="50" HorizontalAlignment="Right" VerticalAlignment="Top" Background="Transparent">
                <MenuItem Name="About"  Background="Transparent">
                    <MenuItem.Header>
                        <Label>?</Label>
                    </MenuItem.Header>
                </MenuItem>
            </Menu>

            <DockPanel Margin="0,0,0,20" Grid.Row="1" Grid.ColumnSpan="6">
                <StatusBar DockPanel.Dock="Top" Background="LemonChiffon"
                       
                       Height="Auto">
                    <StatusBar.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="150"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="50"></RowDefinition>
                                </Grid.RowDefinitions>
                            </Grid>
                        </ItemsPanelTemplate>
                    </StatusBar.ItemsPanel>
                    <StatusBarItem Grid.Column="0" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
                        <Label Name="RoleEditStatus" FontSize="15" Background="LightGreen" BorderBrush="Black"
                   BorderThickness="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
                   Opacity="1" FontWeight="Bold" Content="{Binding ElementName=SecurityRoleListItemSource, Path=SelectedItem}"
                   Height="auto" MaxHeight="100" Grid.Column="0" Margin="5,0,5,0"
                           
                           />
                    </StatusBarItem>
                    <Separator Grid.Column="1"></Separator>
                    <StatusBarItem Background="LemonChiffon" Grid.Column="2" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
                        <Button Name="ButtonSaveRole" Content="Save role"
                        Tag="{Binding ElementName=SecurityRoleListItemSource, Path=SelectedItem}"
                        IsEnabled="{Binding ElementName=SecurityRoleListItemSource, Path=SelectedItem.RoleChanged, FallbackValue=false}"                    
                        Margin="5,5,5,5" FontSize="15"
                        Background="Green" Foreground="White" FontWeight="Bold"/>
                    </StatusBarItem>
                </StatusBar>
            </DockPanel>


            <!--<Grid Grid.Column="4">
                    <StackPanel Orientation="Horizontal">
                   
                    </StackPanel>
                </Grid>-->
            <ScrollViewer Name="ScrollViewerMainWindow"
                          Grid.Row="2" Grid.ColumnSpan="6" HorizontalScrollBarVisibility="Visible"  
                         
                          >
                <Grid Name="NestedGrid">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition ></RowDefinition>
                        <RowDefinition ></RowDefinition>
                        <RowDefinition ></RowDefinition>
                        <RowDefinition ></RowDefinition>
                        <RowDefinition ></RowDefinition>
                        <RowDefinition ></RowDefinition>
                        <RowDefinition ></RowDefinition>
                        <RowDefinition ></RowDefinition>
                        <RowDefinition ></RowDefinition>
                        <RowDefinition ></RowDefinition>
                    </Grid.RowDefinitions>

                    <Grid Name="UserRolesHeader" Grid.Column="0" Grid.ColumnSpan="5" Grid.Row="2" >
                        <StackPanel Name="allElements" Margin="5" Grid.Column="0" Grid.ColumnSpan="5" >

                            <StackPanel Orientation="Horizontal" Margin="10,0,10,0">
                                <Button  Grid.Row="0" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="Black" >                                
                                </Button>
                            </StackPanel>
                            <ListView Margin="10" x:Name="SecurityRoleListItemSource" IsSynchronizedWithCurrentItem="True" SelectedItem="{Binding Id}" SelectionMode="Single"
                          MaxHeight="600"
                                     ItemsSource="{Binding}" >
                                <ListView.ItemContainerStyle>
                                    <Style TargetType="ListViewItem">
                                        <Style.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter Property="Background" Value="Transparent"/>
                                                <Setter Property="BorderBrush" Value="Transparent"/>
                                            </Trigger>
                                        </Style.Triggers>
                                        <Setter Property="Focusable" Value="false"/>
                                    </Style>
                                </ListView.ItemContainerStyle>
                                <ListView.View>
                                    <GridView>                                   
                                        <GridViewColumn Width="180" DisplayMemberBinding="{Binding DisplayName}" >
                                            <GridViewColumn.Header>
                                                <GridViewColumnHeader Tag="DisplayName"
                                                     >Displayname
                                                </GridViewColumnHeader>
                                            </GridViewColumn.Header>
                                        </GridViewColumn>
                                        <GridViewColumn Width="250" DisplayMemberBinding="{Binding FilteredADObjectNameIsMemberOfThisRole}" >
                                            <GridViewColumn.Header>
                                                <GridViewColumnHeader Tag="FilteredADObjectNameIsMemberOfThisRole" >Active Directory User- or Groupmembership</GridViewColumnHeader>
                                            </GridViewColumn.Header>
                                        </GridViewColumn>
                                        <GridViewColumn Width="200" DisplayMemberBinding="{Binding Path=Description}" >
                                            <GridViewColumn.Header>
                                                <GridViewColumnHeader Tag="Description" >Description</GridViewColumnHeader>
                                            </GridViewColumn.Header>
                                        </GridViewColumn>
                                        <GridViewColumn Width="auto" DisplayMemberBinding="{Binding Path=LastModified}" >
                                            <GridViewColumn.Header>
                                                <GridViewColumnHeader Tag="LastModified" >Last Modified</GridViewColumnHeader>
                                            </GridViewColumn.Header>
                                        </GridViewColumn>
                                        <GridViewColumn Width="auto" DisplayMemberBinding="{Binding Path=LastModifiedBy}" >
                                            <GridViewColumn.Header>
                                                <GridViewColumnHeader Tag="LastModifiedBy" >Last Modified By</GridViewColumnHeader>
                                            </GridViewColumn.Header>
                                        </GridViewColumn>
                                    </GridView>
                                </ListView.View>
                            </ListView>
                        </StackPanel>
                    </Grid>

                    <Expander Name="ExpanderBasicRoleInformation"  Grid.Column="6" Grid.RowSpan="8" Grid.Row="2"
                          ExpandDirection="Right" IsExpanded="False">
                        <StackPanel Grid.Column="6" Grid.RowSpan="8" Grid.Row="0"
                            Width="300">

                            <GroupBox Header="Role profile" >

                                <Label Name="lblEditRoleProfileText">
                                    <TextBlock Name="TxtBlockRoleProfileDescription"
                             Foreground="DarkGray" TextWrapping="Wrap"
                                       Text="{Binding ElementName=SecurityRoleListItemSource, Path=SelectedItem.SecurityObject.Profile.Description}"></TextBlock>
                                </Label>
                            </GroupBox>
                            <GroupBox Header="Role name" >

                                <TextBox Name="txtBoxRollenname" Text="{Binding ElementName=SecurityRoleListItemSource, Path=SelectedItem.DisplayName}"
                             TextWrapping="Wrap" MaxLength="256" Height="40" VerticalScrollBarVisibility="Auto"   
                                 >

                                </TextBox>
                            </GroupBox>
                            <GroupBox Header="Role description" >

                                <TextBox Name="txtBoxRollenbeschreibung" Text="{Binding ElementName=SecurityRoleListItemSource, Path=SelectedItem.Description}"
                             TextWrapping="Wrap" MaxLength="4000" Height="100" VerticalScrollBarVisibility="Auto" AcceptsReturn="True"                             
                               
                                 >

                                </TextBox>
                            </GroupBox>
                            <GroupBox Header="Users" >
                                <ScrollViewer>
                                    <ListView Name="listviewRoleUsers" ItemsSource="{Binding ElementName=SecurityRoleListItemSource, Path=SelectedItem.SecurityObject.Users}"
                                  MaxHeight="400" Height="200" SelectionMode="Single"></ListView>
                                </ScrollViewer>
                            </GroupBox>
                            <StackPanel Orientation="Horizontal" Margin="5,5,5,5">
                                <Button Margin="0,0,5,0" Content="add"
                                IsEnabled="{Binding ElementName=listviewRoleUsers, Path=IsEnabled}"
                                
                                Tag="{Binding ElementName=SecurityRoleListItemSource, Path=SelectedItem}"></Button>
                                <Button Tag="{Binding ElementName=listviewRoleUsers, Path=SelectedItem}"
                                 Margin="0,0,5,0" Content="remove"
                                IsEnabled="{Binding ElementName=listviewRoleUsers, Path=IsEnabled}"></Button>
                            </StackPanel>

                        </StackPanel>
                    </Expander>

                    <!-- Templates -->
                    <Grid Grid.ColumnSpan="5" Grid.Row="3">

                        <StackPanel>

                            <GroupBox >
                                <Grid Name="MainGridTemplates" >
                                    <StackPanel>

                                        <Label FontSize="24">Form Templates</Label>
                                        <Expander>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition></ColumnDefinition>
                                                    <ColumnDefinition></ColumnDefinition>
                                                    <ColumnDefinition></ColumnDefinition>
                                                    <ColumnDefinition></ColumnDefinition>
                                                    <ColumnDefinition></ColumnDefinition>
                                                </Grid.ColumnDefinitions>

                                                <StackPanel Grid.Column="0" Grid.ColumnSpan="5">
                                                   
                                                    <ListView Margin="10" Name="TemplateSettingsList" Grid.Column="0" Grid.ColumnSpan="5"
                                                    SelectionMode="Multiple"  ScrollViewer.VerticalScrollBarVisibility="Auto" Height="300"
                                                    
                                                          >
                                                        <ListView.ItemContainerStyle>
                                                            <Style TargetType="ListViewItem">
                                                                <Style.Triggers>
                                                                    <Trigger Property="IsMouseOver" Value="True">
                                                                        <Setter Property="Background" Value="Transparent"/>
                                                                        <Setter Property="BorderBrush" Value="Transparent"/>
                                                                    </Trigger>
                                                                </Style.Triggers>
                                                                <Setter Property="Focusable" Value="false"/>
                                                            </Style>
                                                        </ListView.ItemContainerStyle>

                                                        <ListView.View>
                                                            <GridView >
                                                                
                                                                <GridViewColumn Width="180" DisplayMemberBinding="{Binding DisplayName}" >
                                                                    <GridViewColumn.Header>
                                                                        <GridViewColumnHeader Tag="DisplayName" >DisplayName</GridViewColumnHeader>
                                                                    </GridViewColumn.Header>
                                                                </GridViewColumn>
                                                                <GridViewColumn Width="220" DisplayMemberBinding="{Binding Description}" >
                                                                    <GridViewColumn.Header>
                                                                        <GridViewColumnHeader Tag="Description" >Description</GridViewColumnHeader>
                                                                    </GridViewColumn.Header>
                                                                </GridViewColumn>
                                                                <GridViewColumn Width="120" DisplayMemberBinding="{Binding Name}" >
                                                                    <GridViewColumn.Header>
                                                                        <GridViewColumnHeader Tag="Name">Name</GridViewColumnHeader>
                                                                    </GridViewColumn.Header>
                                                                </GridViewColumn>
                                                                

                                                            </GridView>

                                                        </ListView.View>

                                                    </ListView>
                                                   
                                                </StackPanel>
                                            </Grid>
                                        </Expander>
                                    </StackPanel>
                                </Grid>
                            </GroupBox>
                        </StackPanel>
                    </Grid>
                   
                  

                </Grid>
            </ScrollViewer>
        </Grid>


    • Edited by Sysadmin21 Wednesday, May 15, 2019 12:21 PM
    Wednesday, May 15, 2019 12:15 PM

Answers

  • thank you for your support. I found my problem. I only had to set VerticalAlignment="Top" and after that all worked for me.

    thanks anyway.

    • Marked as answer by Sysadmin21 Friday, May 17, 2019 9:35 AM
    Friday, May 17, 2019 9:35 AM

All replies


  • Hi    Sysadmin21,

    >>Scrollviewer for nestedGrid dynamic height from parent grid or window 

    Have you tried the following way?

    Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=grid }}"

    Besides, I copy your code and cannot reproduce your issue(without any steps description). 

    I suggest you can upload your demo to OneDrive(Including your test material) and with a detailed description about the results including any exception messages. We can download it and debugging.


    Best Regards

    Yong Lu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 16, 2019 6:13 AM
    Moderator
  • thank you for your support. I found my problem. I only had to set VerticalAlignment="Top" and after that all worked for me.

    thanks anyway.

    • Marked as answer by Sysadmin21 Friday, May 17, 2019 9:35 AM
    Friday, May 17, 2019 9:35 AM