更改启动页面 [英] Changing the StartUp Page
问题描述
我目前正在我的应用程序中创建一个设置页面,让用户可以选择主页面的UI。我有两个页面,每个页面包含一个不同的UI。它们是"MainPage.xaml"。和"OldMainPage.xaml"。我想知道如何在Visual Basic中编写
来改变启动页面,具体取决于"MainPage"的radiobutton是否可用。或"OldMainPage"的"radiobutton"或"radiobutton"在设置页面中是否选中。
Hi, I am currently making a settings page in my app which lets the user pick the main page's UI. I have two pages one of each contain a different UI. They are "MainPage.xaml" and the "OldMainPage.xaml". I was wondering how I can program
in Visual Basic to change the startup page depending on if the radiobutton for "MainPage" or radiobutton for "OldMainPage" in the settings page is checked or not.
我已经找到了如何实现这一目标的方法,但是它们似乎都没有效果。我尝试了UriMapper,这是我在App.xaml.vb页面中到目前为止的代码片段:
I have looked up ways on how to achieve this, however none of them seem to work. I tried UriMapper and here is the snippet of code I have thus far in my App.xaml.vb page:
公共类UriMapper
继承UriMapperBase
私人天使作为字符串
Public Overrides Function MapUri(uri As Uri)As Uri
Dim tempUri = uri.ToString()
如果(tempUri.Contains(QUOT; ViewfinderLaunch"))然后
              &NBSP ; Dim referenceSettings As New Settings
如果referenceSettings.radioButton7.IsChecked然后
                 &NBSP ; 返回新的URI(QUOT; /MainPage.xaml" ;, UriKind.Relative)
                 elseif的referenceSettings.radioButton8.IsChecked然后
                 &NBSP ; 返回新的URI(QUOT; /OldMainPage.xaml" ;, UriKind.Relative)
                结束如果
结束如果
返回uri
结束功能
结束类
Public Class UriMapper
Inherits UriMapperBase
Private tempuri As String
Public Overrides Function MapUri(uri As Uri) As Uri
Dim tempUri = uri.ToString()
If (tempUri.Contains("ViewfinderLaunch")) Then
Dim referenceSettings As New Settings
If referenceSettings.radioButton7.IsChecked Then
Return New Uri("/MainPage.xaml", UriKind.Relative)
ElseIf referenceSettings.radioButton8.IsChecked Then
Return New Uri("/OldMainPage.xaml", UriKind.Relative)
End If
End If
Return uri
End Function
End Class
稍后,我将其置于"Private Sub InitializePhoneApplication()"下:
And later on, I have put this under"Private Sub InitializePhoneApplication()":
RootFrame.UriMapper = New UriMapper()
RootFrame.UriMapper = New UriMapper()
我不确定我做错了什么,所以任何帮助都会受到极大关注。谢谢!
I am not sure if I am doing anything wrong, so any help would be greatly appriciated. Thank you!
推荐答案
您好,可以使用以下代码片段:
Hi there, you can use the following code snippet:
var tipo = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetTypes()
where type.Name.ToLower() == "YOUR_MAIN_PAGE_NAME".ToLower()
select type).FirstOrDefault();
if (tipo != null)
{
//test contains your XAML file
object test = Activator.CreateInstance(tipo);
//Do some stuff here...
}
我的解决方案是C#,但想法是一样的。
My solution is in C# but the idea is the same.
希望有所帮助。
这篇关于更改启动页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!