【问题标题】:What are people using instead of IMultiValueConverters in Windows 8?人们在 Windows 8 中使用什么来代替 IMultiValueConverters?
【发布时间】:2013-07-01 22:55:18
【问题描述】:

我正在将现有 WPF 应用程序移植到 Windows 8 应用程序。

在 WPF 应用程序中,我们大量使用 MultiValue 转换器来允许我们创建由 UI 元素属性和视图模型属性(河马对象的权重和项目控件的实际宽度)组合而成的值,以实现良好的 UI 效果。

但是,Windows 8 没有多值转换器。

由于我正在移植一个应用程序,我真的不想显着更改我的视图模型或 Xaml。

如何以最少的痛苦和重写来复制多值控制器功能?

【问题讨论】:

  • I'm porting an existing WPF application to a Windows 8 application. - 我真的为你感到难过。到目前为止,WinRT XAML 功能集甚至不如 Silverlight 功能集。这意味着它只是完整 WPF 功能集的一小部分。这意味着您将不得不求助于各种可怕的黑客来使其正常工作。
  • WinRT 是新的 CompactFramework,它拥有一切,除了............一切
  • 我用脏话代替。很多:-)
  • 作为一种解决方法,您可以考虑使用此答案中描述的方法 - stackoverflow.com/questions/20229214/…
  • @Sevenate 这看起来很有用,谢谢。如果我回到 WinRT 领域,我会试一试。

标签: xaml mvvm windows-8


【解决方案1】:

我的方法是公开 VM 的静态单例实例;例如:

public class MainViewModel : INotifyPropertyChanged
{
    private static MainViewModel _mvm;
    public static MainViewModel MVM
    {
        get
        {
            if (_mvm == null)
                _mvm = new MainViewModel();

            return _mvm;
        }
    }

然后简单地通过整个虚拟机:

<Button Command="{Binding MyCommand}" CommandParameter="{Binding MVM}">Run Command</Button>        

它不是多重绑定,但它确实允许您传递多个参数。

【讨论】:

  • 问题不在于如何将视图模型传递给转换器。它将视图模型和视图属性传递给转换器。 (哦,您似乎根本没有使用转换器,这令人困惑,因为问题是关于转换器的)。
  • 答案是WinRT不支持。我只是想我会提供另一种方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-15
  • 2011-10-02
  • 2011-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-24
相关资源
最近更新 更多