2017-02-28 53 views
2

這個問題不僅僅是一個數據問題,而是一個整體。有一個簡單的辦法把的您可以使用擴展器來覆蓋WPF中的其他可視化樹元素嗎?

<Expander>(contents)</Expander> 

元素在彈出窗口或別的東西,使其剛好覆蓋在上面的其他因素?

XAML:(我只是做了一個簡單的for循環來填充在構造函數中的「交通線」的一個視圖模型綁定,否則大多數虛擬機爲空)

<Window x:Class="MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:local="clr-namespace:MVVM" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="600" Width="800"> 
    <Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
    <Grid> 
     <Expander ExpandDirection="Down" IsExpanded="True" HorizontalAlignment="Stretch"> 
     <Expander.Header> 
      <TextBlock TextAlignment="Left" HorizontalAlignment="Center" VerticalAlignment="Center" Text="LOCATIONS" FontWeight="Bold"/> 
     </Expander.Header> 
     <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" Height="300" HorizontalAlignment="Stretch"> 
      <ItemsControl ItemsSource="{Binding Locs}" > 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
       <CheckBox Margin="5" Content="{Binding}" /> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
      </ItemsControl> 
     </ScrollViewer> 
     </Expander> 
    </Grid> 
    <Label Grid.Row="1" Height="100" Content="Test Content" FontSize="32" /> 
    </Grid> 
</Window> 

啓動應用程序和看起來不錯。

Start of Control

單擊擴展,現在它縮短了,但它跳躍的文字了。我在視覺樹中理解這是默認行爲,但是是否有一種簡單的方法可以將其包含在某個覆蓋圖中,如彈出窗口,在其摺疊時不會使其他文本跳轉?

End of Control

回答

1

您可以在ExpanderHeight屬性設置爲一個固定值,以保留其垂直空間的前期。

或者你可以把ScrollViewerPopup,如:

<Expander x:Name="expander" ExpandDirection="Down" IsExpanded="True" HorizontalAlignment="Stretch"> 
    <Expander.Header> 
     <TextBlock TextAlignment="Left" HorizontalAlignment="Center" VerticalAlignment="Center" Text="LOCATIONS" FontWeight="Bold"/> 
    </Expander.Header> 
    <Popup PlacementTarget="{Binding ElementName=expander}" 
        Placement="Bottom" 
        IsOpen="{Binding IsExpanded, ElementName=expander}"> 
     <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" Height="300" HorizontalAlignment="Stretch" 
           Background="White"> 
      <ItemsControl> 
       <CheckBox Margin="5" Content="1" /> 
       <CheckBox Margin="5" Content="2" /> 
       <CheckBox Margin="5" Content="3" /> 
       <CheckBox Margin="5" Content="4" /> 
       <CheckBox Margin="5" Content="5" /> 
      </ItemsControl> 
     </ScrollViewer> 
    </Popup> 
</Expander> 

<Label Grid.Row="1" Height="100" Content="Test Content" FontSize="32" /> 

您可能需要閱讀這是能夠在移動彈出時Expander移動:

How can I move a WPF Popup when its anchor element moves?

+0

沒錯我想要什麼,謝謝。 – djangojazz