条件文本格式XAML WP8
是否可以在XAML中设置textblock控件的某种形式的条件格式,以便根据文本更改文本的颜色(例如text=“good”然后设置为绿色,text=“bad”然后设置文本为红色。)条件文本格式XAML WP8,xaml,windows-phone-8,formatting,conditional,Xaml,Windows Phone 8,Formatting,Conditional,是否可以在XAML中设置textblock控件的某种形式的条件格式,以便根据文本更改文本的颜色(例如text=“good”然后设置为绿色,text=“bad”然后设置文本为红色。) 我尝试了一些示例,但它们似乎不起作用,可能是因为WP8的工作方式不同。一种简单的方法是使用DataTriggers查看,如: 名称空间: xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://sche
我尝试了一些示例,但它们似乎不起作用,可能是因为WP8的工作方式不同。一种简单的方法是使用
DataTrigger
s查看,如:
名称空间:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
<TextBlock x:Name="TheText" Text="{Binding Blah}"/>
<i:Interaction.Triggers>
<ei:DataTrigger Value="Red"
Binding="{Binding Text, ElementName=TheText}">
<ei:ChangePropertyAction PropertyName="Foreground"
Value="Red" />
</ei:DataTrigger>
<ei:DataTrigger Value="Blue"
Binding="{Binding Text, ElementName=TheText}">
<ei:ChangePropertyAction PropertyName="Foreground"
Value="Blue" />
</ei:DataTrigger>
</i:Interaction.Triggers>
</TextBlock>
控制:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
<TextBlock x:Name="TheText" Text="{Binding Blah}"/>
<i:Interaction.Triggers>
<ei:DataTrigger Value="Red"
Binding="{Binding Text, ElementName=TheText}">
<ei:ChangePropertyAction PropertyName="Foreground"
Value="Red" />
</ei:DataTrigger>
<ei:DataTrigger Value="Blue"
Binding="{Binding Text, ElementName=TheText}">
<ei:ChangePropertyAction PropertyName="Foreground"
Value="Blue" />
</ei:DataTrigger>
</i:Interaction.Triggers>
</TextBlock>
或者你可以用代码连接条件。希望这能有所帮助。你能发布一些你已经尝试过的例子吗?这有助于了解哪些不起作用。