2012-05-16 23 views
2

我想在XAML中使用手風琴控制,但無法更改用作默認的深藍色背景。我已經成功地遇到了一些其他人遇到同樣的問題,但沒有發佈解決方案。我迄今發現的唯一答案涉及使用Expression Studio,但不幸的是,我不擁有一個副本。無法更改XAML中的藍色背景手風琴

查看下面的設計器代碼,目前沒有很多,我試着在每個元素上設置背景屬性,但沒有得到任何結果。

<Window x:Class="Test.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="289" 
    Width="500" 
    xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"> 
    <Grid> 
     <my:Accordion HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
      <my:AccordionItem x:Name="item1" Header="Item 1"> 
       <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
       </Grid> 
      </my:AccordionItem> 
      <my:AccordionItem x:Name="item2" Header="Item 2"> 

      </my:AccordionItem> 
      <my:AccordionItem x:Name="item3" Header="Item 3"> 

      </my:AccordionItem> 
     </my:Accordion>   
    </Grid> 
</Window> 

回答

3

看看這個有同樣問題的人的MSDN Forum thread。另請注意,此控件質量爲Preview,根據CodePlex等同於Alpha版本。

從以上鍊接:

的關鍵部分是結合到實際的外電網。出於某種原因,手風琴項目沒有爲內部網格提供寬度/高度來延伸,因此您必須將其綁定到「更高」的位置。


我測試了它和它的工作,它給的Object reference not set to an instance of an object它編譯和運行雖然設計錯誤。

<Grid> 
    <my:Accordion HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
     <my:AccordionItem x:Name="item1" Header="Item 1"> 
      <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White" 
       Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth}" 
       Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}}, Path=ActualHeight}"> 
      </Grid> 
     </my:AccordionItem> 
     <my:AccordionItem x:Name="item2" Header="Item 2"> 
      <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White" 
       Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth}" 
       Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}}, Path=ActualHeight}"> 
      </Grid> 
     </my:AccordionItem> 
     <my:AccordionItem x:Name="item3" Header="Item 3"> 
      <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White" 
       Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth}" 
       Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}}, Path=ActualHeight}"> 
      </Grid> 
     </my:AccordionItem> 
    </my:Accordion> 
</Grid> 
+0

謝謝,這沒有訣竅:)建立一次後,我的設計師不再顯示錯誤。 – rastating

+0

@ int0x90很高興能有所幫助。 –