2013-09-03 40 views
6

My expanding menuWPF cách làm cho nội dung di chuyển giãn nở

Xin chào Tôi muốn thêm điều khiển WPF vào ElementHost trong ứng dụng WinForms của tôi. Hành vi kiểm soát của tôi được mô tả trên hình ảnh. Tôi muốn mở rộng bất kỳ expander làm cho kiểm soát treeview của tôi thay đổi kích cỡ để kích thước nhỏ hơn. Và ngay từ đầu, tôi muốn những người mở rộng của tôi bị sụp đổ.

Tôi đã cố gắng sth như thế:

<UserControl x:Class="LeftPane" 
     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" > 
<Grid VerticalAlignment="Stretch" Margin="3,3,3,3"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*"/>    
    </Grid.RowDefinitions> 
    <TreeView Grid.Row="0" Name="treeView1" VerticalAlignment="Stretch" > 

    </TreeView> 
    <StackPanel Grid.Row="1" Name="StackPanel1" VerticalAlignment="Bottom"> 
     <ListBox SelectedIndex="1"> 
      <ListBoxItem VerticalAlignment="Stretch"> 
       <Expander Grid.Row="1" ExpandDirection="Down" Header="expander1" VerticalAlignment="Stretch" Name="expander1" IsExpanded="False"> 
        <ListBox> 
         <ListBoxItem Content="Unit 1"/> 
         <ListBoxItem Content="Unit 2"/> 
        </ListBox> 
       </Expander> 
      </ListBoxItem> 
      <ListBoxItem VerticalAlignment="Stretch"> 
       <Expander Grid.Row="2" ExpandDirection="Down" Header="expander2" VerticalAlignment="Stretch" Name="expander2" IsExpanded="False"> 
        <ListBox> 
         <ListBoxItem Content="Unit 1"/> 
         <ListBoxItem Content="Unit 2"/> 
        </ListBox> 
       </Expander> 
      </ListBoxItem> 
     </ListBox> 
    </StackPanel> 
</Grid> 

và:

public void AddControl(ElementHost host) 
    { 
     this.parentHost = host; 
     host.Child = this; 
     this.Height = host.Size.Height; 
     treeView1.MaxHeight = this.Height - 60; 

    } 

Nhưng nó không hoạt động một cách chính xác. Điều gì là nhiều hơn tôi muốn điều khiển này thay đổi kích cỡ trong khi tôi thay đổi kích cỡ cửa sổ winForms của tôi.

bất cứ ai có thể giúp tôi làm thế nào để thiết lập aligment, vv

Trả lời

5

Đây là cách tôi sẽ đạt được điều này ... đầu tiên, tôi sẽ thay đổi Grid như sau:

<Grid.RowDefinitions> 
    <RowDefinition Height="*" /> 
    <RowDefinition Height="Auto" /> 
    <RowDefinition Height="Auto" /> 
</Grid.RowDefinitions> 

này sẽ cung cấp hai Expander điều khiển với không gian nhiều như họ cần và TreeView với tất cả các phần còn lại:

<TreeView Grid.Row="0" Name="treeView1" /> 
<Expander Grid.Row="1" Header="expander1" Name="expander1" IsExpanded="False"> 
    <ListBox> 
     <ListBoxItem Content="Unit 1"/> 
     <ListBoxItem Content="Unit 2"/> 
    </ListBox> 
</Expander> 
<Expander Grid.Row="2" Header="expander2" Name="expander2" IsExpanded="False"> 
    <ListBox> 
     <ListBoxItem Content="Unit 1"/> 
     <ListBoxItem Content="Unit 2"/> 
    </ListBox> 
</Expander> 
+1

Nó làm cho một thiết bị mở rộng xuất hiện trên một thiết bị khác. Và những gì là nhiều hơn kiểm soát không quy mô khi tôi thay đổi kích cỡ cửa sổ WinForms mẹ. – santBart

+0

@santBart giả sử Sheridan có nghĩa là Grid.Row = "2" trên thiết bị mở rộng thứ hai – Alex

+0

Cảm ơn @voo. Xin lỗi, lỗi của tôi ... Tôi đã cập nhật mã của tôi ngay bây giờ. – Sheridan

0

Để thực hiện kiểm soát của tôi thay đổi kích thước, Tôi đã chuyển thuộc tính ElementHost Dock thành Fill.

Các vấn đề liên quan