2
 <controls:PanoramaItem Header="Aylık" Foreground="White">
        <Grid x:Name="monthlyPanaromaGrid" >
            <Grid.Resources>
                <Style TargetType="ListBoxItem" x:Key="ListItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </Grid.Resources>
            <ScrollViewer HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch">
                <ListBox x:Name="monthlyItemListBox"  ScrollViewer.VerticalScrollBarVisibility="Auto" >
                    <ListBox.ItemTemplate >
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
                                <TextBlock Text="{Binding Id}"  FontSize="24" />
                                <TextBlock Text="    " FontSize="24" />
                                <TextBlock Text="{Binding Name}" FontSize="24" />
                                <TextBlock Text="    " FontSize="24" />
                                <TextBlock Text="{Binding Surname}" FontSize="24" />
                                <TextBlock Text="    " FontSize="24" />
                                <TextBlock Text="{Binding Age}" FontSize="24" />
                                <TextBlock Text="    " FontSize="24" />
                                <TextBlock Text="{Binding Status}" FontSize="24" />
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </ScrollViewer>
        </Grid>
    </controls:PanoramaItem>

我尝试了包含 50 个成员的列表,但我无法查看滚动查看器,这可能会导致问题吗?谢谢我在这里看到了一些答案,我试过但没有工作(改变高度......等)谢谢。

4

1 回答 1

4

ListBox已经有一个ScrollViewer,这两个控件将争夺您的操作。

删除外部ScrollViewer,或设置ScrollViewer.VerticalScrollBarVisibility="Disabled"您的ListBox以禁用滚动。

并且不确定你是否使用那些TextBlocksfor Margin,但你应该Margin直接设置,或者使用ColumnDefinitions和 a Grid

<controls:PanoramaItem Header="Aylık" Foreground="White">
        <Grid x:Name="monthlyPanaromaGrid" >
            <Grid.Resources>
                <Style TargetType="ListBoxItem" x:Key="ListItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </Grid.Resources>
                <ListBox x:Name="monthlyItemListBox" HorizontalAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Auto" >
                    <ListBox.ItemTemplate >
                        <DataTemplate>
                            <Grid HorizontalAlignment="Stretch">
                              <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="*" />
                              </Grid.ColumnDefinitions>

                                <TextBlock Text="{Binding Id}" Grid.Column="0" FontSize="24" />
                                <TextBlock Text="{Binding Name}" Grid.Column="1" FontSize="24" />
                                <TextBlock Text="{Binding Surname}" Grid.Column="2" FontSize="24" />
                                <TextBlock Text="{Binding Age}" Grid.Column="3" FontSize="24" />
                                <TextBlock Text="{Binding Status}" Grid.Column="4" FontSize="24" />
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
        </Grid>
    </controls:PanoramaItem>

或者

<controls:PanoramaItem Header="Aylık" Foreground="White">
        <Grid x:Name="monthlyPanaromaGrid" >
            <Grid.Resources>
                <Style TargetType="ListBoxItem" x:Key="ListItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </Grid.Resources>
                <ListBox x:Name="monthlyItemListBox" HorizontalAlignment="Stretch"  ScrollViewer.VerticalScrollBarVisibility="Auto" >
                    <ListBox.ItemTemplate >
                        <DataTemplate>
                            <Grid HorizontalAlignment="Stretch">
                              <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                              <ColumnDefinition Width="Auto" />
                              <ColumnDefinition Width="Auto" />
                              <ColumnDefinition Width="Auto" />
                              <ColumnDefinition Width="Auto" />
                              </Grid.ColumnDefinitions>

                                <TextBlock Text="{Binding Id}" Grid.Column="0" FontSize="24" />
                                <TextBlock Text="{Binding Name}" Margin="48,0,0,0" Grid.Column="1" FontSize="24" />
                                <TextBlock Text="{Binding Surname}" Margin="48,0,0,0" Grid.Column="2" FontSize="24" />
                                <TextBlock Text="{Binding Age}" Margin="48,0,0,0" Grid.Column="3" FontSize="24" />
                                <TextBlock Text="{Binding Status}" Margin="48,0,0,0" Grid.Column="4" FontSize="24" />
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
        </Grid>
    </controls:PanoramaItem>
于 2012-07-13T03:26:14.970 回答