[英]Bind to default property value of another control style definition in xaml
我有一個CustomControl
並且想要具有TextBox
默認樣式定義的默認值。 我不知道那是否有可能。
到目前為止,這是我一直未嘗試的嘗試。 但是在這里您可以看到我的想法。
我的默認實現可更改TextBox
的默認樣式(例如,在app.xaml中將其全局應用)
<Style TargetType="TextBox">
<Setter Property="BorderThickness" Value="2"/>
</Style>
在這里,我想獲取值“ 2”。
<Style TargetType="controls:CustomControl">
<Setter Property="BorderThickness" Value="{Binding Source={x:Static TextBox.BorderThicknessProperty}}"/>
</Style>
該默認值BorderThickness
一個財產TextBox
在默認樣式定義的TextBox
,其最終被應用到的實例TextBox
在運行時。
因此,您不能執行以下操作:
<Style TargetType="controls:CustomControl">
<Setter Property="BorderThickness" Value="{Binding Source={x:Static TextBox.BorderThicknessProperty}}"/>
</Style>
...除非您綁定到使用默認樣式的TextBox
的實際實例。
您可以查看TextBox
的默認模板,並只需復制其默認BorderThickness
屬性值1
:
<Style TargetType="controls:CustomControl">
<Setter Property="BorderThickness" Value="1"/>
</Style>
顯然,您還可以從多個Style
綁定到一個類的屬性,例如:
<Style TargetType="controls:CustomControl">
<Setter Property="BorderThickness" Value="{Binding Thickness, Source={StaticResource settings}}"/>
</Style>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.