【发布时间】:2021-12-29 04:09:45
【问题描述】:
我有两个具有相同属性的文本框。例如:
<!-- TextBox1 -->
<TextBox Foreground="Red"
Style="{StaticResource MaterialTextBox}"
materialDesign:HintAssist.Foreground="Blue"
materialDesign:HintAssist.HintOpacity="100"
materialDesign:TextFieldAssist.UnderlineBrush="Green">
<materialDesign:HintAssist.Hint>
<TextBlock Foreground="{DynamicResource Lime}"
Text="SomeHint1" />
</materialDesign:HintAssist.Hint>
</TextBox>
<!-- TextBox2 -->
<TextBox Foreground="Red"
Style="{StaticResource MaterialTextBox}"
materialDesign:HintAssist.Foreground="Blue"
materialDesign:HintAssist.HintOpacity="100"
materialDesign:TextFieldAssist.UnderlineBrush="Green">
<materialDesign:HintAssist.Hint>
<TextBlock Foreground="{DynamicResource Lime}"
Text="SomeHint2" />
</materialDesign:HintAssist.Hint>
</TextBox>
请注意,唯一的区别是 MaterialDesign:HintAssist.Hint 属性的 "SomeHint1" 和 "SomeHint2" 字符串。
所以我想我可以为此设计一个样式:
<Style TargetType="TextBox" x:Key="TextBoxWithMaterialHintStyle" BasedOn="{StaticResource MaterialTextBox}">
<Setter Property="Foreground" Value="Red" />
<Setter Property="materialDesign:HintAssist.Foreground" Value="Blue" />
<Setter Property="materialDesign:HintAssist.HintOpacity" Value="100" />
<Setter Property="materialDesign:TextFieldAssist.UnderlineBrush" Value="Green" />
<Setter Property="materialDesign:HintAssist.Hint">
<Setter.Value>
<TextBlock Foreground="{DynamicResource Blue}"
Text="???" />
</Setter.Value>
</Setter>
</Style>
注意 TextBlock 的 Text 属性在我的风格中是 "???"。
我不知道如何将 "SomeHint1" 或 "SomeHint2" 传递给 Style 并进一步传递给 TextBlock 的 Text 属性。
有解决办法吗?
【问题讨论】:
-
View Model/Code 后面的属性?
标签: wpf parameters material-design wpf-style