lok*_*oki 9 silverlight xaml silverlight-4.0 c#-4.0
我有2页我需要导航mainpage.xaml到login.page xaml但它抛出我 对象引用未设置为对象的实例.在Root.Children.Clear(); ....
我在App.xaml中添加了这些代码:
private void Application_Startup(object sender, StartupEventArgs e)
{
Grid myGrid = new Grid();
myGrid.Children.Add(new MainPage());
this.RootVisual = myGrid;
}Run Code Online (Sandbox Code Playgroud)
而且我在main.xaml上添加了一些代码以导航到LoginUI.xaml
namespace Gen.CallCenter.UI
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
Grid Root = ((Grid)(this.Parent));
Root.Children.Clear();
Root.Children.Add(new LoginUI());
}
}
}Run Code Online (Sandbox Code Playgroud)
如何将main.xaml导航到LoginUI.xaml?
小智 12
让我们假设你正在查看的MainPage.xaml,然后你想打开另一个名为XAML页面newPage.xaml通过点击Button或ImageEdit在MainPage.xaml,这里是你应该在里面写了快速的解决方案MainPage.xaml.cs:
private void imageEdit1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
newPage mynewPage = new newPage(); //newPage is the name of the newPage.xaml file
this.Content = mynewPage;
}
Run Code Online (Sandbox Code Playgroud)
这与我合作.
tex*_*ex5 11
就像AnthonyWJones所说,你需要使用导航框架.
首先,您需要System.Windows.Controls.Navigation在项目中添加引用并在MainPage.xaml中引用它
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
Run Code Online (Sandbox Code Playgroud)
然后,您将需要一个框架,您可以在其中切换不同的XAML页面.像这样的东西:
<navigation:Frame x:Name="navFrame" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Source=”/Views/First.xaml” />
Run Code Online (Sandbox Code Playgroud)
现在在MainPage.xaml的某个地方你可以有一个带标签的Button
<Button Click="Button_Click" Tag="/Views/Second.xaml" Content="Second" />
并且在Button_Click事件处理程序中,您可以切换显示的内容navFrame.
private void Button_Click(object sender, RoutedEventArgs e)
{
Button theButton = sender as Button;
string url = theButton.Tag.ToString();
this.navFrame.Navigate(new Uri(url, UriKind.Relative));
}
Run Code Online (Sandbox Code Playgroud)
在这里要注意很酷的事情是,通过使用NavigationFramework浏览器的前进和后退按钮完美的工作,并根据不同的XAML页面上的地址栏更新网址您目前的:)
| 归档时间: |
|
| 查看次数: |
47448 次 |
| 最近记录: |