我試圖找出一種方式來應用樣式到文本框元素,當它不包含文本。我希望TextBox在其包含或不包含任何文本時具有不同的背景色(例如)。將樣式應用到Windows Phone文本框時,它不包含文本
由於觸發器不是我可以在Silverlight(afaik)中使用的東西,還有另一種方法可以做到這一點嗎?最好不用爲此行爲編寫一個自定義的TextBox實現。謝謝。
我結束了使用默認行爲(ConditionBehavior):
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<i:Interaction.Behaviors>
<ec:ConditionBehavior>
<ec:ConditionalExpression>
<ec:ComparisonCondition LeftOperand="{Binding Text, ElementName=textBox}" RightOperand="" Operator="NotEqual"/>
</ec:ConditionalExpression>
</ec:ConditionBehavior>
</i:Interaction.Behaviors>
<ec:ChangePropertyAction PropertyName="Background" Value="{StaticResource PhoneTextBoxBrush}" />
</i:EventTrigger>
<i:EventTrigger EventName="TextChanged">
<i:Interaction.Behaviors>
<ec:ConditionBehavior>
<ec:ConditionalExpression>
<ec:ComparisonCondition LeftOperand="{Binding Text, ElementName=textBox}" RightOperand="" Operator="Equal"/>
</ec:ConditionalExpression>
</ec:ConditionBehavior>
</i:Interaction.Behaviors>
<ec:ChangePropertyAction PropertyName="Background" Value="Transparent" />
</i:EventTrigger>
</i:Interaction.Triggers>
創建一個轉換器綁定到文本屬性,風格 – 2012-01-10 20:05:50