2013-09-03 5 views
6

My expanding menuWPF कैसे बनाने के लिए विस्तारक कदम सामग्री

हाय मैं अपने WinForms आवेदन में ElementHost को WPF नियंत्रण जोड़ना चाहते हैं। मेरे नियंत्रण का व्यवहार चित्र पर चित्रित किया गया है। मैं किसी भी विस्तारक का विस्तार करना चाहता हूं कि मेरा वृक्षदृश्य नियंत्रण छोटे आकार में बदल जाए। और शुरुआत में मैं चाहता हूं कि मेरे विस्तारक ढह जाएंगे।

ऐसा

मैं कोशिश कर रहा था sth:

<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> 

और:

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

    } 

लेकिन इसे सही ढंग से काम नहीं करता। जब मैं अपनी WinForms विंडो का आकार बदलता हूं तो मैं इस नियंत्रण का आकार बदलना चाहता हूं।

किसी को भी मेरी मदद कर सकते स्थापित करने के लिए कैसे aligment आदि

उत्तर

5

यह मैं यह कैसे प्राप्त होता है ... पहले, मुझे निम्न के Grid बदल जाएगा:

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

यह प्रदान करेगा के रूप में ज्यादा और अंतरिक्ष के रूप में वे की जरूरत है बाकी सब के साथ TreeView के साथ दो Expander नियंत्रण:

<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

यह एक विस्तारक दूसरे पर दिखाई देता है। और जब मैं पैरेंट WinForms विंडो का आकार बदलता हूं तो नियंत्रण अधिक स्केल नहीं होता है। – santBart

+0

@ सैंटबार्ट मान लीजिए शेरिडन का अर्थ है ग्रिड। पंक्ति = "2" दूसरे विस्तारक – Alex

+0

धन्यवाद @voo। क्षमा करें, मेरी गलती ... मैंने अभी अपना कोड अपडेट कर लिया है। – Sheridan

0

मेरे नियंत्रण आकार बदलने योग्य बनाने के लिए, मैंने ElementHost प्रॉपर्टी डॉक को भरने के लिए स्विच किया।

संबंधित मुद्दे