我正在使用mvvmcross.plugins.visibil.
我有" xmlns:valueConverters =" use:app.uwp.converters
<views:MvxWindowsPage.Resources>
<valueConverters:VisibilityConverter x:Key="Visibility" />
<valueConverters:InverseVisibilityConverter x:Key="InvertedVisibility" />
</views:MvxWindowsPage.Resources>
我有以下布局
<Button Content="Log In" Command="{Binding LoginCommand}" Visibility="{Binding IsBusy, Converter{StaticResource InvertedVisibility}}" />
<ProgressRing Visibility="{Binding IsBusy, Converter={StaticResource Visibility}}" />
我的ViewModel具有ISBUSY属性
bool _isBusy;
public bool IsBusy
{
get { return _isBusy; }
set
{
_isBusy = value;
RaisePropertyChanged(() => IsBusy);
}
}
当我更改ISBUSY属性时,我会得到一个例外,说"指定的演员是无效的。"
我需要做什么才能使它工作?
编辑堆栈跟踪
at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
at MvvmCross.Core.ViewModels.MvxNotifyPropertyChanged.<>c__DisplayClass11_0.<RaisePropertyChanged>b__0()
at MvvmCross.Uwp.Views.MvxWindowsMainThreadDispatcher.RequestMainThreadAction(Action action, Boolean maskExceptions)
at MvvmCross.Core.ViewModels.MvxNotifyPropertyChanged.RaisePropertyChanged(PropertyChangedEventArgs changedArgs)
at MvvmCross.Core.ViewModels.MvxNotifyPropertyChanged.RaisePropertyChanged[T](Expression`1 property)
at intelliSPEC.Core.ViewModels.LoginViewModel.set_IsBusy(Boolean value)
at intelliSPEC.Core.ViewModels.LoginViewModel.<Login>d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MvvmCross.Core.ViewModels.MvxAsyncCommandBase.<ExecuteConcurrentAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MvvmCross.Core.ViewModels.MvxAsyncCommandBase.<ExecuteAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MvvmCross.Core.ViewModels.MvxAsyncCommandBase.<Execute>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
我注意到您在第一个Binding
中有错字 - Converter
之后有一个丢失的=
符号。
但是,我认为主要问题可能是您使用的是MVVMCross转换器而不是本地转换器。MVVMCROSS值转换器是跨平台解决方案,如果您使用西藏绑定,则在所有平台上工作。
但是,如果要使用本机UWP绑定,则必须在转换器周围添加本机Windows包装器,以便它实现API所需的仅Windows IValueConverter
接口。为此,请先在您的核心和UWP项目中安装MvvmCross.Plugin.Visibility
软件包,然后您只需在UWP项目中的某个地方创建以下类:
public class VisibilityConverter :
MvxNativeValueConverter<MvxVisibilityValueConverter> { }
public class InverseVisibilityConverter :
MvxNativeValueConverter<MvxInvertedVisibilityValueConverter> { }
我通常将所有这些"本机"类放在一个文件ConvertersNativeConverters.cs
中,但这只是一个约定。您不必为课程提供任何其他实施。如果您在绑定中使用转换器,则应按预期工作。我已经成功地以这种方式运行您的代码。
还要确保在UWP项目中创建Bootstrap类:
public class VisibilityPluginBootstrap
: MvxPluginBootstrapAction<MvvmCross.Plugins.Visibility.PluginLoader>
{
}