1

即使在折叠状态下,如何设置扩展器以显示它包含的一些内容?我有以下代码片段,任何人都可以指出对此代码的更改吗?

<Window x:Class="UI2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="358" Width="300">
<TabControl>
    <TabItem Header="Buga Buga">
        <StackPanel>
            <Expander ClipToBounds="False">
                <ListBox Name="lstProcesses"
                         MinHeight="60">
                </ListBox>
            </Expander>
        </StackPanel>
    </TabItem>
</TabControl>

谢谢

4

2 回答 2

2

听起来 Expander 不是您应该在这种情况下使用的控件。Expander 有一个标题和内容,如下所示:

<Expander Header="Visible all the time">
    <TextBlock Text="Hidden until expanded" />
</Expander>

在我看来,您想要一个有时设置为特定高度的控件,而在其他时间不受限制。

我认为您可以通过将 a ToggleButton(Expander 在内部也使用)绑定到MaxHeight您的ListBox.

在Kaxaml中尝试这样的事情:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:diag="clr-namespace:System.Diagnostics;assembly=System">

  <Page.Resources>
    <!-- A way of getting some test data in Kaxaml -->
    <ObjectDataProvider x:Key="Processes"
                        MethodName="GetProcesses"
                        ObjectType="{x:Type diag:Process}" />
  </Page.Resources>

  <StackPanel>
    <ToggleButton Name="Expand" Content="Expand" />
    <ListBox Name="lstProcesses" 
             ItemsSource="{Binding Source={StaticResource Processes}}"
             DisplayMemberPath="ProcessName">
      <ListBox.Style>
        <Style TargetType="ListBox">
          <Style.Triggers>
            <DataTrigger Binding="{Binding ElementName=Expand, Path=IsChecked}"
                         Value="False">
              <Setter Property="MaxHeight" Value="60" />
            </DataTrigger>
          </Style.Triggers>
        </Style>
      </ListBox.Style>
    </ListBox>
  </StackPanel>
</Page>
于 2009-07-28T06:05:49.007 回答
0

这是一个快速示例,说明如何将折叠文本(标题)添加到扩展器中包含的列表框中的选定项目:

<Expander ClipToBounds="False">
    <ListBox Name="lstProcesses"
                 MinHeight="60">
    </ListBox>
    <Expander.Header>
        <TextBlock Text="{Binding SelectedItem, ElementName=lstProcesses}"/>
    </Expander.Header>
</Expander>
于 2009-07-28T15:14:26.737 回答