Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的 WPF 应用程序中有一个 TextBox,背景颜色为"Blue"。当它获得焦点时,默认情况下背景颜色变为“白色”。当 TextBox 获得焦点时,我希望背景颜色具有另一种颜色(例如"DodgerBlue")。
我在网上能找到的都是样式或模板的惊人示例,它们定义了 TextBox 的所有可能的 VisualStates。
是否无法创建仅针对特定情况的简短模板(即当 TextBox 具有焦点时)?
谢谢。
您可以使用简单的样式触发器:
<TextBox> <TextBox.Style> <Style TargetType="{x:Type TextBox}"> <Style.Triggers> <Trigger Property="IsFocused" Value="True"> <Setter Property="Background" Value="Tomato" /> </Trigger> </Style.Triggers> </Style> </TextBox.Style> </TextBox>
那应该做...