简体   繁体   中英

What are people using instead of IMultiValueConverters in Windows 8?

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?

My approach was to expose a static singleton instance of the VM; for example:

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

            return _mvm;
        }
    }

Then simple pass the whole VM through:

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

It's not multibinding, but it does allow you to pass multiple parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM