Caliburn.Micro.Xamarin.Forms.View.SetContentProperty()堆栈溢出异常

Caliburn.Micro.Xamarin.Forms.View.SetContentProperty()堆栈溢出异常,xamarin.forms,caliburn.micro,Xamarin.forms,Caliburn.micro,我正在开发一个Xamarin.Forms应用程序,并尝试根据“Hello Screens”示例切换同一视图模型的视图。我已经在WPF中成功地使用CM多次,但在Xamarin中它对我不起作用。表单视图模型为“LessonsViewModel”,包含以下LessonsView: <?xml version="1.0" encoding="utf-8" ?> <ContentView xmlns="http://xamarin.com/schemas/2014/forms"

我正在开发一个Xamarin.Forms应用程序,并尝试根据“Hello Screens”示例切换同一视图模型的视图。我已经在WPF中成功地使用CM多次,但在Xamarin中它对我不起作用。表单视图模型为“LessonsViewModel”,包含以下LessonsView:

<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:cal="clr-namespace:Caliburn.Micro.Xamarin.Forms;assembly=Caliburn.Micro.Platform.Xamarin.Forms"
             x:Class="MyCompany.FreshmanLevel.LessonView">
  <ContentView cal:View.Model="{Binding}" cal:View.Context="{Binding CurrentLesson, Mode=TwoWay}"></ContentView>
</ContentView>
我有一个带有以下xaml文件的“Lesson”文件夹(即“LessonViewModel”减去“ViewModel”)

LessonOne.xaml
LessonTwo.xaml
LessonThree.xaml
如果我使用:

<ContentView cal:View.Model="{Binding}" cal:View.Context="LessonThree">

一切正常。但是绑定到一个变量名,如下所示:

<ContentView cal:View.Model="{Binding}" cal:View.Context="{Binding CurrentLesson, Mode=TwoWay}">

导致在VS的输出控制台中出现以下错误:

Stack overflow: IP: 0x1213d7b05, fault addr: 0x0
at Caliburn.Micro.Xamarin.Forms.View.SetContentProperty (object,object) <IL 0x00019, 0x0016d>
at Caliburn.Micro.Xamarin.Forms.View.OnModelChanged (Xamarin.Forms.BindableObject,Caliburn.Micro.DependencyPropertyChangedEventArgs) <IL 0x00033, 0x00258>
at Caliburn.Micro.DependencyPropertyHelper/<>c__DisplayClass0_0.<RegisterAttached>b__0 (Xamarin.Forms.BindableObject,object,object) <IL 0x00017, 0x00132>
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty,Xamarin.Forms.BindableObject/BindablePropertyContext,object,bool,Xamarin.Forms.BindableObject/SetValueFlags,bool) [0x00108] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:584
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty,object,Xamarin.Forms.BindableObject/SetValueFlags,Xamarin.Forms.BindableObject/SetValuePrivateFlags) [0x0014b] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:378
at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) [0x0020c] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindingExpression.cs:177
at Xamarin.Forms.BindingExpression.Apply (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty) [0x0006b] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindingExpression.cs:76
at Xamarin.Forms.Binding.Apply (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty) [0x00042]
 in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Binding.cs:113
堆栈溢出:IP:0x1213d7b05,故障地址:0x0
位于Caliburn.Micro.Xamarin.Forms.View.SetContentProperty(对象,对象)
在Caliburn.Micro.Xamarin.Forms.View.OnModelChanged(Xamarin.Forms.BindableObject,Caliburn.Micro.DependencyPropertyChangedEventArgs)中
在Caliburn.Micro.DependencyPropertyHelper/c__显示类0_0.b_0(Xamarin.Forms.BindableObject,object,object)
在C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.BindableProperty/BindablePropertyContext,object,bool,Xamarin.Forms.BindableObject/SetValueFlags,bool中的Xamarin.Forms.BindableObject.SetValueActual(Xamarin.Forms.BindableObject/BindablePropertyContext,object,bool)[0x00108]处
在C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject:378中的Xamarin.Forms.BindableObject.SetValueCore(Xamarin.Forms.BindableProperty,object,Xamarin.Forms.BindableObject/SetValueFlags,Xamarin.Forms.BindableObject/SetValuePrivateFlags,Xamarin.Forms.BindableObject/SetValuePrivateFlags)[0x0014b]处
在C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindingExpression.cs:177中的Xamarin.Forms.BindableObject(对象,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool)[0x0020c]
在C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindingExpression.cs:76中的Xamarin.Forms.BindingExpression.Apply(对象,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty)[0x0006b]处
在Xamarin.Forms.Binding.Apply(对象,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty)[0x00042]
在C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Binding.cs:113中
有人知道这里发生了什么吗

编辑:据我所知,这个问题似乎源于这样一个事实,即公共属性“CurrentLesson”实际上没有作为绑定语句的结果被读入。我在一个普通的WPF应用程序中重新创建了这个问题,并意识到在cal:View.Context=“{Binding}”之前列出cal:View.Model=“{Binding}”会导致这种情况下的问题,因为需要在解析cal:View.Model之前读入上下文值


然而,我在我的Xamarin表单应用程序中进行了更正,它仍然出错。如果设置断点,则在“OnContextChanged”被触发之前,cal:View.Context-attached属性甚至没有读取CurrentLesson的值,因此在“static bool SetContentPropertyCore(object targetLocation,object View)”中出错。

u将枚举或字符串传递给该绑定?传递具有以下值的枚举“LessonOne”、“LessonTwo”、“LessonTwo”、“LessonTwo”"... 如果我在没有绑定语句的情况下硬编码这些值中的任何一个,它们都会按预期工作。那么这是否意味着绑定
CurrentLesson
该枚举类型?正确。。CurrentLesson是枚举类型的公共属性。请尝试绑定到字符串,看看这是否有帮助!将枚举或字符串传递给该绑定?传递具有以下值“LessonOne”、“LessonTwo”、“LessonThree”的枚举。。。如果我在没有绑定语句的情况下硬编码这些值中的任何一个,它们都会按预期工作。那么这是否意味着绑定
CurrentLesson
该枚举类型?正确。。CurrentLesson是枚举类型的公共属性。请尝试绑定到字符串,看看这是否有帮助!
Stack overflow: IP: 0x1213d7b05, fault addr: 0x0
at Caliburn.Micro.Xamarin.Forms.View.SetContentProperty (object,object) <IL 0x00019, 0x0016d>
at Caliburn.Micro.Xamarin.Forms.View.OnModelChanged (Xamarin.Forms.BindableObject,Caliburn.Micro.DependencyPropertyChangedEventArgs) <IL 0x00033, 0x00258>
at Caliburn.Micro.DependencyPropertyHelper/<>c__DisplayClass0_0.<RegisterAttached>b__0 (Xamarin.Forms.BindableObject,object,object) <IL 0x00017, 0x00132>
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty,Xamarin.Forms.BindableObject/BindablePropertyContext,object,bool,Xamarin.Forms.BindableObject/SetValueFlags,bool) [0x00108] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:584
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty,object,Xamarin.Forms.BindableObject/SetValueFlags,Xamarin.Forms.BindableObject/SetValuePrivateFlags) [0x0014b] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:378
at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) [0x0020c] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindingExpression.cs:177
at Xamarin.Forms.BindingExpression.Apply (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty) [0x0006b] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindingExpression.cs:76
at Xamarin.Forms.Binding.Apply (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty) [0x00042]
 in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Binding.cs:113