(XAML)UserControl在usercontrol中,listview没有滚动条并显示整个内容

时间:2014-12-31 06:28:11

标签: c# wpf xaml user-controls

我想将两个用户控件放入另一个用户控件中。这是我想要的用户控件。

<UserControl x:Class="Project.MainModule.Views.ReportView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:v="clr-namespace:Project.MainModule.Views"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="800">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="120"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <v:ReportCommandsView Grid.Row="0"></v:ReportCommandsView>
     <v:LogItemListView Grid.Row="1" ></v:LogItemListView>
</Grid>
</UserControl>

第一个ReportCommandsView工作正常。但是,当我放入第二个用户控件时,我遇到了问题。它有一个ListView,在列表视图中,它有一个gridview来显示项目。这是xaml。

<UserControl x:Class="Project.MainModule.Views.LogItemListView"
         x:Name="LogListView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<ListView Name="LogItemListListView" FontSize="14"  Grid.Row="0"
              ItemsSource="{Binding LogItems}" 
              SelectedItem="{Binding Mode=TwoWay, Path=CurrentLogItem}"
              AlternationCount="2"
              BorderThickness="0" Width="Auto"
              IsSynchronizedWithCurrentItem="True" 
              AutomationProperties.AutomationId="LogItemListGrid" 
              >

    <ListView.View>
            <GridView AllowsColumnReorder="true" ColumnHeaderToolTip="Log Items View" >
                <GridViewColumn Header="ID" DisplayMemberBinding="{Binding Path=ID}" Width="45"/>
                <GridViewColumn Header="Category"  DisplayMemberBinding="{Binding Path=Category.Description}" Width="120" />
                <GridViewColumn Header="Institution"  DisplayMemberBinding="{Binding Path=Institution.Description}" Width="140" />
                <GridViewColumn Header="Asset"  DisplayMemberBinding="{Binding Path=AssetCode}" Width="65" />
                <GridViewColumn Header="Reader"  DisplayMemberBinding="{Binding Path=Reader}" Width="100" />
                <GridViewColumn Header="Create Date"  DisplayMemberBinding="{Binding Path=CreateDate}" Width="170" />
            </GridView>
        </ListView.View>
    </ListView>
</UserControl>

我发现在第二个usercontrol的listview中,显示的数据却没有滚动条。因为它显示所有数据。数据位于屏幕底部。我试图设置最大高度,它可以工作,滚动条出来了。但这对我不利。我需要在屏幕尺寸改变时进行处理。我该怎么办?

0 个答案:

没有答案