2010-05-12 36 views
0

我想要一個Expander,只有當用戶點擊標題圖標時才展開/摺疊它的內容。 (而不是整個標頭可點擊。)定製WPF擴展器;只使圖標可點擊不是整個標題

我是否必須重新定義控件Template才能做到這一點?它會是什麼樣子?
我在哪裏可以找到控件的標準模板/樣式?

謝謝你的時間。

+0

我相信這是一個重複:http://stackoverflow.com/questions/1396153/preventing-a-wpf-expander-from-expanding-when-header-is-clicked。你應該能夠在那裏找到你的解決方案。 :) – 2010-05-12 20:10:15

回答

0

我發佈了一個解決方案,我的問題here(與本評論相同的鏈接)。

2

實際上有一個比修改模板簡單得多的XAML解決方案。在這種情況下,請勿使用Expander的標題屬性。相反,用自己的樣式的TextBlock覆蓋擴展器。

<Application.Resources> 
    <Style x:Key="ExpanderHeader" TargetType="{x:Type TextBlock}"> 
     <Setter Property="Height" Value="22" /> 
     <Setter Property="Margin" Value="21,0,0,0" /> 
     <Setter Property="Padding" Value="9,3,0,0" /> 
     <Setter Property="HorizontalAlignment" Value="Stretch" /> 
     <Setter Property="VerticalAlignment" Value="Top" /> 
    </Style> 
</Application.Resources> 

<Grid> 
    <Expander> 
     <TextBlock Text="I am some content. I have disowned my default header." Margin="10,5" /> 
    </Expander> 
    <TextBlock Text="I'm filling in for the default header. You'll like me better anyway." 
       Style="{StaticResource ResourceKey=ExpanderHeader}"/> 
</Grid> 
相關問題