5

I'm porting an existing WPF application to a Windows 8 application.

In the WPF application we make considerable use of MultiValue convertors to allow us to create values that are combinations of UI element properties and viewmodel properties (the weight of a hippo object and the actualWidth of an itemscontrol) to achieve nice UI effects.

Windows 8, however, doesn't have a MultiValue convertor.

Since I'm porting an application I don't really want to significantly change my viewmodels or Xaml.

How can I replicate Multivalue controller functionality with a minimum amount of pain and rewriting?

4

1 回答 1

0

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

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

            return _mvm;
        }
    }

然后简单地通过整个VM:

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

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

于 2014-05-19T16:51:39.157 回答