Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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
Wpf 有没有办法使用多重绑定更改文本块的前景?_Wpf_Textblock_Multibinding - Fatal编程技术网

Wpf 有没有办法使用多重绑定更改文本块的前景?

Wpf 有没有办法使用多重绑定更改文本块的前景?,wpf,textblock,multibinding,Wpf,Textblock,Multibinding,我需要根据三个属性更改文本块的前景。我使用带转换器的多重绑定来实现它。转换器正确返回值,但前景不变 <TextBlock Margin="10,1,0,1" Grid.Column="1" Grid.ColumnSpan="2" FontSize="15.5" Text="{Binding Path=FullName}" TextTrimming="CharacterEllipsis" HorizontalAlignment="Stretch" Vertic

我需要根据三个属性更改文本块的前景。我使用带转换器的多重绑定来实现它。转换器正确返回值,但前景不变

<TextBlock
  Margin="10,1,0,1"
  Grid.Column="1"
  Grid.ColumnSpan="2"
  FontSize="15.5"
  Text="{Binding Path=FullName}"
  TextTrimming="CharacterEllipsis"
  HorizontalAlignment="Stretch"
  VerticalAlignment="Center">
  <TextBlock.FontWeight>
      <MultiBinding Converter="{StaticResource FontWeightConverter}">
         <Binding ElementName="MessageCountBorder" Path="Visibility"/>
         <Binding Path="IsMuted"/>
      </MultiBinding>
  </TextBlock.FontWeight>
  <TextBlock.Foreground>
      <MultiBinding Converter="{StaticResource ForegroundConverter}">
          <Binding Path="TypeId"/>
          <Binding Path="IsMuted"/>
          <Binding Path="UserOnlineStatus"/>
      </MultiBinding>
  </TextBlock.Foreground>
</TextBlock>

XAML和转换器代码看起来都不错。实际上,转换器在其中一种情况下返回一个字符串,这不是一个可接受的输出,但就我所见,这个条件是不可达到的,所以应该可以。我猜其中一个属性“TypeId”,“IsMuted”。。。更新事件值时,不会引发事件。即使未实现INPC接口,绑定最初也会工作,但当绑定属性更新时,它们未来的值永远不会更改

public class MyClass : INotifyPropertyChanged
{
    private bool isMuted;

    public bool IsMuted
    {
        get { return isMuted; }
        set
        {
            if (isMuted != value)
            {
                isMuted = value;
                OnPropertyChanged("IsMuted");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected void OnPropertyChanged(string prN)
    {
        if (this.PropertyChanged != null)
            this.PropertyChanged(this, new PropertyChangedEventArgs(prN));
    }
}

return“white”将返回白色字符串,而不是画笔。至少在这种情况下,转换器无法返回正确的值。我尝试返回画笔和字符串。没有用@Andy。那可能没什么好处。我们只是使用转换器中的这3个属性作为前景颜色。据我所知,这里不需要使用INPC接口,除非我们正在更改属性值。无论如何,感谢zaphod-ii的帮助。您可以尝试打开输出窗口,查找任何绑定错误。确保在工具>选项>调试>输出窗口>数据绑定中启用了它们。
public class MyClass : INotifyPropertyChanged
{
    private bool isMuted;

    public bool IsMuted
    {
        get { return isMuted; }
        set
        {
            if (isMuted != value)
            {
                isMuted = value;
                OnPropertyChanged("IsMuted");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected void OnPropertyChanged(string prN)
    {
        if (this.PropertyChanged != null)
            this.PropertyChanged(this, new PropertyChangedEventArgs(prN));
    }
}