如何在单视图WPF中使用差异视图模型进行多重绑定?

我遇到这样的问题: 我有2个用于显示进度视图的视图模型(假设视图模型A负责进度视图A,而视图模型B负责进度视图B) 现在在视图C中,我想绑定到那些视图模型,并且只要激活了其中一个模型的布尔值( ShowProgress ),我都希望在视图C中显示进度视图A或B

当前解决方案就像单绑定。 但是出于某种原因,我想更改为多重绑定,但是我在这里遇到了困难。

有人可以帮助我吗?

这是单绑定的代码。

  <Grid Grid.Row="0"
        Grid.RowSpan="3"
        Grid.Column="0"
        Grid.ColumnSpan="3"
        Background="Transparent"
        Visibility="{Binding A.ShowProgress,Converter={x:Static WpfConverters:Converters.BooleanToVisibility}}"
        ZIndex="100">
    <Views3:ProgressView DataContext="{Binding Path=A.ProgressViewModel}" IsShown="{Binding RelativeSource={RelativeSource AncestorType={x:Type Grid},Mode=FindAncestor},Path=DataContext.A.ShowProgress}" />
  </Grid>
  <Grid Grid.Row="0"
        Grid.RowSpan="3"
        Grid.Column="0"
        Grid.ColumnSpan="3"
        Background="Transparent"
        Visibility="{Binding B.ShowProgress,Converter={x:Static WpfConverters:Converters.BooleanToVisibility}}"
        ZIndex="200">
    <Views3:ProgressView DataContext="{Binding Path=B.SaveProgressViewModel}" IsShown="{Binding RelativeSource={RelativeSource AncestorType={x:Type Grid},Path=B.ShowProgress}" />
  </Grid>
ptpstao 回答:如何在单视图WPF中使用差异视图模型进行多重绑定?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3109092.html

大家都在问