我正在将现有的 WPF 应用程序移植到 Windows 8 应用程序。
在 WPF 应用程序中,我们大量使用 MultiValue 转换器来允许我们创建由 UI 元素属性和 View 模型属性(河马对象的权重和项目控件的实际宽度)组合而成的值,以实现良好的 UI 效果。
但是,Windows 8 没有 MultiValue 转换器。
由于我正在移植一个应用程序,我真的不想显着改变我的 View 模型或 Xaml。
如何以最少的痛苦和重写来复制多值 Controller 功能?
最佳答案
我的方法是公开 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>
它不是多重绑定(bind),但它确实允许您传递多个参数。
关于xaml - 人们在 Windows 8 中使用什么来代替 IMultiValueConverters?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17461747/