Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/windows-phone-7/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml 相对资源自绑定在控件上工作,但不在样式设置器内_Xaml_Windows Phone 7_Windows Phone 8_Windows Phone - Fatal编程技术网

Xaml 相对资源自绑定在控件上工作,但不在样式设置器内

Xaml 相对资源自绑定在控件上工作,但不在样式设置器内,xaml,windows-phone-7,windows-phone-8,windows-phone,Xaml,Windows Phone 7,Windows Phone 8,Windows Phone,这是针对Windows Phone 8的 假设我有一组TextBlocks,我想根据它们绑定到的文本更改它们的前景色 if (text == "0") return Red; else return Green; 我可以使用相对源绑定来实现这一点: <TextBlock Foreground="{Binding Text, Converter={StaticResource TextBrushConverter}, RelativeSource={RelativeSource S

这是针对Windows Phone 8的

假设我有一组
TextBlocks
,我想根据它们绑定到的文本更改它们的前景色

if (text == "0")
  return Red;
else
  return Green;
我可以使用相对源绑定来实现这一点:

<TextBlock Foreground="{Binding Text, Converter={StaticResource TextBrushConverter}, RelativeSource={RelativeSource Self}}" Text="{Binding SomeText}" />

但如果我将其移动到样式设置器,它将不再像预期的那样工作:

<Style x:Name="MyStyle" TargetType="TextBlock">
    <Style.Setters>
        <Setter Property="Foreground" 
                Value="{Binding Text, 
                    Converter={StaticResource TextBrushConverter}, 
                    RelativeSource={RelativeSource Self}}" />
    </Style.Setters>
</Style>

<TextBlock Style="{StaticResource MyStyle}" Text="{Binding SomeText}" />


为什么这样不行?重新使用这种样式(实际上是一套样式)会很好。

您是否尝试了
TemplatedParent
而不是
Self