在我的 Silverlight 应用程序中,我有 TabControl,选项卡控件具有以下项:
<controls:TabItem Header="{Binding Localization.Shift1}" Style="{StaticResource PanelBarTabItemStyle}" IsTabStop="False">
<local:DienstDetailItemControl DataContext="{Binding Shift1, Mode=TwoWay, Converter= {StaticResource DebugConverter}}"/>
</controls:TabItem>
当我的应用程序启动时 Shift1 属性仍然为空(当用户选择一个选项时它将被填充)。
启动应用程序时出现以下错误:
System.Windows.Data Error: ConvertBack cannot convert value 'null' (type 'null'). BindingExpression: Path='Shift1' DataItem='SDB.Zorgplanner.Client.ViewModels.ViewModels.DienstDetailViewModel' (HashCode=13572818); target element is 'SDB.Zorgplanner.Client.Assets.Controls.DienstDetailItemControl' (Name=''); target property is 'DataContext' (type 'System.Object').. System.MethodAccessException: Attempt by method 'System.Windows.CLRPropertyListener.set_Value(System.Object)' to access method 'SDB.Zorgplanner.Client.ViewModels.ViewModels.DienstDetailViewModel.set_Shift1(SDB.Zorgplanner.UIModel.Dienst)' failed.
bij System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
bij System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
bij System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
bij System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
bij System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
bij System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
bij System.Windows.CLRPropertyListener.set_Value(Object value)
bij System.Windows.PropertyAccessPathStep.set_Value(Object value)
bij System.Windows.Data.BindingExpression.UpdateValue().
关于如何解决这个问题的任何想法?
有没有办法从视图模型中以编程方式设置 tabitems 的数据上下文?