C# Listview正在通用应用程序Windows 10中正确调整大小

C# Listview正在通用应用程序Windows 10中正确调整大小,c#,win-universal-app,C#,Win Universal App,我有一个XAML页面,它被一个网格分解如下: <Grid Background="Green"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions>

我有一个XAML页面,它被一个网格分解如下:

<Grid Background="Green">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
 </Grid>

您需要在ScrollView中包装ListView。这将填充空白区域,并在列表溢出空白区域时添加一个滚动条。

您需要在滚动视图中包装ListView。这将填充空白区域,并在列表溢出空白区域时添加一个滚动条。

我解决了问题。这不是行为上的改变,也不是一个bug

正如有人提到的,他们试图重现问题,但无法重现,我决定也这样做

  • 当我将网格和列表视图直接放在主页上时,我无法复制它

  • 当我将我的网格和列表视图放在子页面(即GridPage)上并将其加载到主页上包含的框架中时,我无法复制它

  • 就在那时,硬币掉了

    在我的代码中,我(第一次)使用了一个SplitView,这个SplitView包含在一个有两行的网格中,愚蠢的是,当我应该为我的汉堡菜单、徽标和标题将第一行设置为Auto时,两行都设置为“Auto”,而第二行应该设置为“*”

    第二次我把第二行改为“*”,问题就解决了。它与包含我最初发布的网格问题的网格页面无关

    <Grid Background="{ThemeResource FocusVisualWhiteStrokeThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
    
    
    
    以下是完整的代码:

    <Grid Background="{ThemeResource FocusVisualWhiteStrokeThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
    
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Border Background="White" 
                Grid.Row="0" 
                Grid.Column="0" 
                Margin="0,10,0,10">
                <ToggleButton Style="{StaticResource SymbolButton}" 
         Foreground="{ThemeResource ApplicationForegroundThemeBrush}"
         FontSize="{ThemeResource ControlContentThemeFontSize}"
         Command="{Binding HamburgerCommand}" >
                    <FontIcon x:Name="Hamburger" 
                     FontFamily="Segoe MDL2 Assets" 
             Glyph="&#xE700;" 
             Foreground="#ff6600" />
                </ToggleButton>
            </Border>
            <Border Background="White" Grid.Row="0" 
             Grid.Column="1" Margin="10,0,0,0">
                <Image Stretch="Fill" Source="{Binding SelectedSection, 
                 Converter={StaticResource SectionImageConverter}}" 
                 Height="20" Width="20" />
            </Border>
            <Border Background="White" 
                Grid.Row="0" 
                Grid.Column="2"
                Margin="10,0,0,0">
                <TextBlock x:Name="Header" Text="{Binding SelectedSection,
                 Converter={StaticResource 
                 SectionTitleConverter}}" 
                 Style="{StaticResource TagLineTextStyle}" 
                 Foreground="#ff6600" 
                 VerticalAlignment="Center" 
                 Margin="10,0,0,0"/>
            </Border>
        </Grid>
    
        <SplitView x:Name="Splitter"
            IsPaneOpen="{Binding IsPageOpen}"  
            DisplayMode="Inline" 
            Grid.Row="1">
            <SplitView.Pane>
                <ListBox x:Name="SectionControl" SelectionMode="Single"
                    ItemsSource="{Binding Sections}"
                    HorizontalAlignment="Left" 
                    Background="White" 
                    BorderThickness="0"
                    VerticalAlignment="Top"
                    SelectedItem="{Binding 
                                        SelectedSection, Mode=TwoWay}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Source="{Binding Converter={StaticResource
                                 SectionImageConverter}}" 
                                 Height="17" Width="17"/>
                                <TextBlock Text="{Binding 
                                 Converter={StaticResource
                                 SectionTitleConverter}}"
                                    Margin="20,0,0,0"
                                    Foreground="#ff6600" />
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                    <Interactivity:Interaction.Behaviors>
                        <Core:EventTriggerBehavior EventName="SelectionChanged">
                            <Core:InvokeCommandAction Command="{Binding
                             ItemClickCommand}" 
                             CommandParameter="{Binding SelectedSection}" />
                        </Core:EventTriggerBehavior>
                    </Interactivity:Interaction.Behaviors>
                </ListBox>
            </SplitView.Pane>
            <SplitView.Content>
                <Frame x:Name="SectionFrame"/>
            </SplitView.Content>
        </SplitView>
    </Grid>
    
    
    

    再次感谢您的反馈/帮助。非常感谢

    我解决了这个问题。这不是行为上的改变,也不是一个bug

    正如有人提到的,他们试图重现问题,但无法重现,我决定也这样做

  • 当我将网格和列表视图直接放在主页上时,我无法复制它

  • 当我将我的网格和列表视图放在子页面(即GridPage)上并将其加载到主页上包含的框架中时,我无法复制它

  • 就在那时,硬币掉了

    在我的代码中,我(第一次)使用了一个SplitView,这个SplitView包含在一个有两行的网格中,愚蠢的是,当我应该为我的汉堡菜单、徽标和标题将第一行设置为Auto时,两行都设置为“Auto”,而第二行应该设置为“*”

    第二次我把第二行改为“*”,问题就解决了。它与包含我最初发布的网格问题的网格页面无关

    <Grid Background="{ThemeResource FocusVisualWhiteStrokeThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
    
    
    
    以下是完整的代码:

    <Grid Background="{ThemeResource FocusVisualWhiteStrokeThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
    
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Border Background="White" 
                Grid.Row="0" 
                Grid.Column="0" 
                Margin="0,10,0,10">
                <ToggleButton Style="{StaticResource SymbolButton}" 
         Foreground="{ThemeResource ApplicationForegroundThemeBrush}"
         FontSize="{ThemeResource ControlContentThemeFontSize}"
         Command="{Binding HamburgerCommand}" >
                    <FontIcon x:Name="Hamburger" 
                     FontFamily="Segoe MDL2 Assets" 
             Glyph="&#xE700;" 
             Foreground="#ff6600" />
                </ToggleButton>
            </Border>
            <Border Background="White" Grid.Row="0" 
             Grid.Column="1" Margin="10,0,0,0">
                <Image Stretch="Fill" Source="{Binding SelectedSection, 
                 Converter={StaticResource SectionImageConverter}}" 
                 Height="20" Width="20" />
            </Border>
            <Border Background="White" 
                Grid.Row="0" 
                Grid.Column="2"
                Margin="10,0,0,0">
                <TextBlock x:Name="Header" Text="{Binding SelectedSection,
                 Converter={StaticResource 
                 SectionTitleConverter}}" 
                 Style="{StaticResource TagLineTextStyle}" 
                 Foreground="#ff6600" 
                 VerticalAlignment="Center" 
                 Margin="10,0,0,0"/>
            </Border>
        </Grid>
    
        <SplitView x:Name="Splitter"
            IsPaneOpen="{Binding IsPageOpen}"  
            DisplayMode="Inline" 
            Grid.Row="1">
            <SplitView.Pane>
                <ListBox x:Name="SectionControl" SelectionMode="Single"
                    ItemsSource="{Binding Sections}"
                    HorizontalAlignment="Left" 
                    Background="White" 
                    BorderThickness="0"
                    VerticalAlignment="Top"
                    SelectedItem="{Binding 
                                        SelectedSection, Mode=TwoWay}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Source="{Binding Converter={StaticResource
                                 SectionImageConverter}}" 
                                 Height="17" Width="17"/>
                                <TextBlock Text="{Binding 
                                 Converter={StaticResource
                                 SectionTitleConverter}}"
                                    Margin="20,0,0,0"
                                    Foreground="#ff6600" />
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                    <Interactivity:Interaction.Behaviors>
                        <Core:EventTriggerBehavior EventName="SelectionChanged">
                            <Core:InvokeCommandAction Command="{Binding
                             ItemClickCommand}" 
                             CommandParameter="{Binding SelectedSection}" />
                        </Core:EventTriggerBehavior>
                    </Interactivity:Interaction.Behaviors>
                </ListBox>
            </SplitView.Pane>
            <SplitView.Content>
                <Frame x:Name="SectionFrame"/>
            </SplitView.Content>
        </SplitView>
    </Grid>
    
    
    

    再次感谢您的反馈/帮助。非常感谢

    您好,当我看到您的评论时,我很有希望,我认为没有必要使用ListView来处理这个问题,但我认为这是值得的,但它不起作用。我刚刚发现一篇文章,我认为这是一个bug,唯一的解决办法是设置高度,但这不是一个解决方案,因为我希望它能在多个设备上工作:请不要:ListView通过其控件模板在内部包含一个ScrollViewer。将其放入另一个滚动视图或堆栈面板将禁用其数据虚拟化功能。正如@Romasz在上面所说的,代码应该可以工作,它一定是你的项目中的其他东西。嗨,当我看到你的评论时,我很有希望,我认为我不认为这是必要的,因为ListView应该处理这个问题,但我认为这是值得的,但它没有工作。我刚刚发现一篇文章,我认为这是一个bug,唯一的解决办法是设置高度,但这不是一个解决方案,因为我希望它能在多个设备上工作:请不要:ListView通过其控件模板在内部包含一个ScrollViewer。将其放入另一个滚动视图或堆栈面板将禁用其数据虚拟化功能。正如上面@Romasz所述,该代码应该可以工作,它必须是您项目中的其他代码。正如我尝试使用simple TextBlock作为数据模板一样,我在设备和模拟器上没有遇到问题。您可以共享一个示例项目吗?正如我尝试使用simple TextBlock作为数据模板一样,我在设备和模拟器上没有遇到问题。你能分享一个示例项目吗?