我試圖做這樣的事情......我的WPF樣式設置器可以使用TemplateBinding嗎?
<Style
x:Key="MyBorderStyle"
TargetType="Border">
<Setter
Property="BorderBrush"
Value="{StaticResource MyBorderBrush}" />
<Setter
Property="Background"
Value="{StaticResource MyBackgroundBrush}" />
<Setter
Property="Padding"
Value="{TemplateBinding Padding}" />
</Style>
...但我得到的錯誤:'Padding' member is not valid because it does not have a qualifying type name.
如何提供一個「合格的類型名」?
注:我試圖做到這一點的原因是,我想在一系列類似的ControlTemplates中包含相同的邊框。
謝謝。
編輯:
嗯,我想這...
<Setter
Property="Padding"
Value="{TemplateBinding GridViewColumnHeader.Padding}" />
...它實際上編譯,但後來當我跑的應用程序,我得到了一個XamlParseException
:
Cannot convert the value in attribute 'Value' to object of type ''.
我想也許合格Padding
與GridViewColumnHeader
(這是我想使用這種風格的ControlTemplate)將工作,但沒有骰子。
編輯2:
那麼,根據對TemplateBinding
的文檔,它說:
Links the value of a property in a control template to be the value of some other exposed property on the templated control.
所以,它聽起來像什麼,我要做的只是普通不可能的。我真的希望能夠爲控件模板中的某些控件創建可重用的樣式,但我猜這些樣式中不能包含模板綁定。
好主意,Shane。謝謝。 – devuxer 2010-06-22 20:54:47