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>

ある時は特定の高さに設定され、他の時は拘束されないコントロールが必要なように思えます。

ToggleButtona (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 に答える