C# 更改App.RootVisual
我有一个主项目,它将根据进行登录的参与者的角色使用MEF加载其他项目,例如: 如果用户名是project1,我将加载project1及其对应的XAP、模型、视图模型和视图 因此,我需要更改App.RootVisual并根据当前项目设置主页 我一直在互联网上寻找解决方案,发现几乎相同的事情都是通过不同的方式完成的,我尝试了以下方法: 首先,我在应用程序启动时将RootVisual设置为网格:C# 更改App.RootVisual,c#,silverlight,C#,Silverlight,我有一个主项目,它将根据进行登录的参与者的角色使用MEF加载其他项目,例如: 如果用户名是project1,我将加载project1及其对应的XAP、模型、视图模型和视图 因此,我需要更改App.RootVisual并根据当前项目设置主页 我一直在互联网上寻找解决方案,发现几乎相同的事情都是通过不同的方式完成的,我尝试了以下方法: 首先,我在应用程序启动时将RootVisual设置为网格: Grid grid = new Grid(); this.RootVisu
Grid grid = new Grid();
this.RootVisual = grid;
grid.Children.Add(new MainPage());
因此,在身份验证方法返回必须加载的项目后,我将执行以下操作:
var grid = App.Current.RootVisual as Grid;
grid.Children.RemoveAt(0);
grid.Children.Add(new Project1MainPage());
我在主页上创建了绑定到DependencyProperty的ContentControl:
<ContentControl Name="region1ContentControl" Content="{Binding Path=MainContent}" Style="{StaticResource ContentControlStyle}" Grid.Row="1" Margin="0,30" />
任何人都知道我能做什么或其他改变UI的解决方案??
希望我的问题清楚,谢谢 听起来像是导航框架和/或棱镜模块的工作 Prism选项-如果项目中的每个角色都是Prism模块,则可以将其加载到模块目录中,并根据角色在必要时显示: 导航框架选项-如果使用System.Windows.Controls.Navigation命名空间中的导航框架作为主页面上的容器,则可以设置UriMapper,并根据需要将框架内容重定向到每个角色页
听起来像是导航框架和/或棱镜模块的工作 Prism选项-如果项目中的每个角色都是Prism模块,则可以将其加载到模块目录中,并根据角色在必要时显示: 导航框架选项-如果使用System.Windows.Controls.Navigation命名空间中的导航框架作为主页面上的容器,则可以设置UriMapper,并根据需要将框架内容重定向到每个角色页
{System.InvalidOperationException: Element is already the child of another element.
em MS.Internal.XcpImports.CheckHResult(UInt32 hr)
em MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)
em MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)
em System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
em System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue)
em System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
em System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
em System.Windows.Data.BindingExpression.SendDataToTarget()
em System.Windows.Data.BindingExpression.SourcePropertyChanged(PropertyPathListener sender, PropertyPathChangedEventArgs args)
em System.Windows.PropertyPathListener.ReconnectPath()
em System.Windows.Data.Debugging.BindingBreakPoint.<>c__DisplayClass4.<BreakOnSharedType>b__3()}
em System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
em System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
em System.Delegate.DynamicInvokeImpl(Object[] args)
em System.Delegate.DynamicInvoke(Object[] args)
em MainPagexaml_9.BindingOperation(Object BindingState, Int32 , Action )