2010-05-01 58 views
0

我有一個列表框內的另一個列表框,在內部列表框中listboxitems的高度可能會增長或縮小。我的問題是,當內部項目縮小外部列表框不會重新呈現其高度。因此 - 在內部列表縮小之前保持先前的高度。ListBoxItem高度沒有得到更新

我在這裏嘗試了這麼多東西,所有類型,選擇的Invalidate中和列表框項目應該更新和更多的去選擇 - 沒有什麼幫助....

誰能請幫助我有了這個?

感謝名單, 吉利

+0

你能發佈一些代碼?內部列表框高度設置爲自動?我假設你想要內部列表框項目增長/縮小,改變它的高度,從而又改變外框的高度。 – CodeWarrior 2010-05-02 03:11:59

回答

0

只爲它赫克我做了以下內容:

<Grid x:Name="LayoutRoot"> 
    <ListBox HorizontalAlignment="Left" Width="283" VerticalAlignment="Top"> 
     <ListBox Margin="0,0,-274,0"> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
     </ListBox> 
     <ListBox Margin="0,0,-274,0"> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
     </ListBox> 
     <ListBox Margin="0,0,-274,0"> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
     </ListBox> 
     <ListBox Margin="0,0,-274,0"> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
      <ListBoxItem Content="Text"/> 
     </ListBox> 
    </ListBox> 
</Grid> 

現在我意識到在列表框在運行時不創建的項目,但我創建一個帶點擊處理器的小按鈕,它將項目添加到其中一箇中間列表框中,並且適當調整所有項目。

如果您發佈您的代碼,我們可以看一下,看看什麼是重擊。

0

藉此例如:

<ListBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="500"> 
     <ListBox x:Name="Item1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300" BorderBrush="Red" BorderThickness="5"> 
      <ListBox.Items> 
       <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300" SizeChanged="OnInnserItemSizeChanged"/> 
       <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300"/> 
       <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300"/> 
      </ListBox.Items> 
     </ListBox> 
     <ListBox x:Name="Item2" BorderBrush="Green" BorderThickness="5" Width="300" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> 
      <ListBox.Items> 
       <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300"/> 
       <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300"/> 
       <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300"/> 
      </ListBox.Items> 
     </ListBox>    
    </ListBox> 

現在,當我運行它,然後點擊「確認」 /「返回」的RichTextBoxes的一個,外部列表框項目延伸,以匹配新的大小 - 但當我刪除新添加的行不會調整回原來的大小...

感謝名單, 吉利

+0

Gili - 我建議您將更新後的問題材料作爲修改放回原始問題中。堆棧溢出的答案將用於提供原始問題的答案,僅此而已。 – jpierson 2011-05-10 02:37:24