1

我有一个 WPF 应用程序,并且我使用扩展器。当我让扩展器折叠时,它一直占据空间。是否可以在 xaml 中释放空间?

这是一些代码:

   <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="3*"></RowDefinition>
        <RowDefinition Height="4*"></RowDefinition>
        <RowDefinition Height="2*"></RowDefinition>
  </Grid.RowDefinitions>
    <wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding IsBusy}" BusyContent="Uploading enrollment data..." Grid.Row="0" />

    <Expander Grid.Row="1" IsExpanded="True" Header="Enrollment Files Upload">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal" Margin="3, 10" Grid.Row="0">
                <TextBlock Text="Agencies:" VerticalAlignment="Center" />
                <ComboBox x:Name="Agencies" DisplayMemberPath="PrimaryName" SelectedValuePath="AgentId" 
                      SelectedItem="{Binding SelectedAgency}"
                      MinWidth="100" Margin="3,0,10,0" VerticalAlignment="Center" />
                <TextBlock Text="Worksheet:" VerticalAlignment="Center" />
                <TextBox x:Name="WorkSheetName" VerticalAlignment="Center" Margin="3,0,10,0" />
                <Button x:Name="UploadFile"
                MinWidth="70"
                Margin="2"
                HorizontalAlignment="Center"
                VerticalAlignment="Center" 
                attachProperties:ButtonIcon.Icon="Resources/Images/add.png"
                Content="Upload File"  IsEnabled="{Binding EnrollmentFiles.Any}"                           
                Style="{StaticResource ImageButtonStyle}" />

                <Button x:Name="EnrollmentDelete"
                    MinWidth="70"
                    Margin="2"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center" 
                    attachProperties:ButtonIcon.Icon="Resources/Images/Remove.png"
                    Content="Delete Enrollment"  IsEnabled="{Binding EnrollmentFiles.Any}"                           
                    Style="{StaticResource ImageButtonStyle}" />
            </StackPanel>

            <c1:C1FlexGrid x:Name="EnrollmentFiles" Grid.Row="1"
                AutoGenerateColumns="False"
                IsReadOnly="True" Width="Auto"
                ItemsSource="{Binding Path=EnrollmentFiles}"
                SelectionMode="Row" KeepCurrentVisible="True"
                SelectedItem="{Binding Path=SelectedEnrollmentFile, Mode=TwoWay}">
...
            </c1:C1FlexGrid>
        </Grid>   
    </Expander>

    <Expander Grid.Row="2" IsExpanded="True" Header="First Data Entry Records">

        <DataGrid x:Name="FirstEntries"
            AutoGenerateColumns="False"
            BaseControls:DataGridExtension.Columns="{Binding FirstEntryGridColumns}"
            CanUserAddRows="False" IsReadOnly="True"
            SelectedItem="{Binding Path=SelectedFirstEntry}">
...
        </DataGrid>

    </Expander>

    <Expander Grid.Row="3" IsExpanded="True" Header="Enrollment Files Upload">

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

            <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.ColumnSpan="3" Margin="3,10">
 ...
            </StackPanel>

            <TextBlock x:Name="SelectedFirstEntry_NameOnAccount" Grid.Row="1" Grid.Column="0"  />
            <TextBlock x:Name="SelectedFirstEntry_AccountNo" Grid.Row="1" Grid.Column="1" Margin="3,0" />
            <TextBlock x:Name="SelectedFirstEntry_MeterNo" Grid.Row="1" Grid.Column="2" Margin="3,0"/>

            <DataGrid x:Name="Findings" Grid.Row="2" 
                 AutoGenerateColumns="False"
                 BaseControls:DataGridExtension.Columns="{Binding FindingsGridColumns}"
                 CanUserAddRows="False">
 ...
            </DataGrid>
        </Grid>
    </Expander>
</Grid>

谢谢

4

2 回答 2

2

扩展器确实折叠但您看不到它,因为您的行定义具有恒定的高度,请尝试:

<RowDefinition Height="auto"></RowDefinition>

(在顶部网格上)

于 2012-08-17T18:25:36.850 回答
0

扩展器控件是一个奇怪的控件。关于使用的空间等,您需要避免一些事情。查看文档

具体来说,

“即使内容折叠,边框也会显示。要设置扩展内容区域的大小,请在 Expander 的内容上设置大小尺寸,或者如果您想要滚动功能,请在包含内容的 ScrollViewer 上设置。”

所以看起来你必须重新考虑你的 UI 并使用滚动查看器的固定内容大小,或者使用带有 3 个选项卡的 TabControl?

于 2012-08-17T20:31:03.187 回答