扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:陶刚编译 来源:天极网 2007年11月4日
关键字:
Partial Public Class Page2 Inherits PageFunction(Of String) Public Sub New() End Sub Public Sub New(ByVal data As String) ' 处理输入的数据 End Sub Private Sub ButtonClick(ByVal sender As Object, _ ByVal e As RoutedEventArgs) Me.RemoveFromJournal = True OnFinish(New ReturnEventArgs(Of String)(txtName.Text)) End Sub End Class |
p2 = New Page2("the string to pass into") p2.InitializeComponent() navWindow.Navigate(p2) |
图10:线性导航。应用程序的这三个页面是线性关系。 |
<Page x:Class="Page1" xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" > <DockPanel> <StackPanel DockPanel.Dock="Left" Background="LightBlue"> <TextBlock Margin="10,10,10,10"> Page 1</TextBlock> </StackPanel> <StackPanel DockPanel.Dock="Right" Background="LightYellow"> <TextBlock Margin="10,10,10,10"> Enter your name</TextBlock> <TextBox Name="txtName" Margin="10,10,10,10" Width="200" HorizontalAlignment="Left"></TextBox> <Button Click="ButtonClick" Name="btnNextPage" Margin="10,10,10,10" Width="80" HorizontalAlignment="Left">Next Page</Button> <Button Click="ButtonClick" Name="btnExit" Margin="10,10,10,10" Width="80" HorizontalAlignment="Left">Exit</Button> <TextBlock Margin="10,10,10,10"> <Inline Name="returnString" /> </TextBlock> </StackPanel> </DockPanel> </Page> |
图11:Page1.xaml。新应用程序的第一个页面,它将使用线性导航。 |
Partial Public Class Page1 Inherits Page Public WithEvents nextPage As Page2 ' 用于保存输入的名字 Private Shared _Name As String Private Sub OnLoaded(ByVal sender As Object, _ ByVal e As RoutedEventArgs) Handles Me.Loaded txtName.Text = _Name End Sub Private Sub ButtonClick(ByVal sender As Object, _ ByVal e As RoutedEventArgs) Dim myApp As NavigationApplication Dim navWindow As NavigationWindow myApp = CType(System.Windows.Application.Current, NavigationApplication) navWindow = CType(myApp.MainWindow, NavigationWindow) ' 导航到下一个页面 If sender.Equals(btnNextPage) Then ' 保存输入的名字 _Name = txtName.Text nextPage = New Page2 nextPage.InitializeComponent() navWindow.Navigate(nextPage) End If ' 退出应用程序 If sender.Equals(btnExit) Then System.Windows.Application.Current.Shutdown() End If End Sub Private Sub nextPage_Return(ByVal sender As Object, _ ByVal args As StringReturnEventArgs) Handles _ nextPage.Return ' 显示后一个窗体中输入的字符串 returnString.Text = "From Page 2: " & args.Result.ToString End Sub End Class |
<StringPageFunction x:Class="Page2" xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" > <DockPanel> <StackPanel DockPanel.Dock="Left" Background="LightBlue"> <TextBlock Margin="10,10,10,10"> Page 2</TextBlock> </StackPanel> <StackPanel DockPanel.Dock="Right" Background="LightYellow"> <TextBlock Margin="10,10,10,10"> Enter your company name</TextBlock> <TextBox Name="txtCompanyName" Margin="10,10,10,10" Width="200" HorizontalAlignment="Left"> </TextBox> <DockPanel> <Button DockPanel.Dock="Left" Click="ButtonClick" Name="btnPreviousPage" Margin="10,10,10,10" Width="80" HorizontalAlignment="Left"> Previous Page</Button> <Button DockPanel.Dock="Right" Click="ButtonClick" Name="btnNextPage" Margin="10,10,10,10" Width="80" HorizontalAlignment="Left"> Next Page</Button> </DockPanel> <Button Click="ButtonClick" Name="btnExit" Margin="10,10,10,10" Width="80" HorizontalAlignment="Left">Exit</Button> <TextBlock Margin="10,10,10,10"> <Inline Name="returnString" /> </TextBlock> </StackPanel> </DockPanel> </StringPageFunction> |
图12:Page2.xaml。应用程序的第二个页面,它给第一个页面返回一个字符串。 |
Partial Public Class Page2 Inherits StringPageFunction Public WithEvents nextPage As Page3 ' 用于保存用户在页面中选择的公司名称 Private Shared _CompanyName As String Private Sub OnLoaded(ByVal sender As Object, _ ByVal e As RoutedEventArgs) Handles Me.Loaded txtCompanyName.Text = _CompanyName End Sub Private Sub ButtonClick(ByVal sender As Object, _ ByVal e As RoutedEventArgs) Dim myApp As NavigationApplication Dim navWindow As NavigationWindow myApp = CType(System.Windows.Application.Current, NavigationApplication) navWindow = CType(myApp.MainWindow,NavigationWindow) ' 导航到下一页 If sender.Equals(btnNextPage) Then _CompanyName = txtCompanyName.Text nextPage = New Page3 nextPage.InitializeComponent() navWindow.Navigate(nextPage) End If If sender.Equals(btnPreviousPage) Then OnFinish(txtCompanyName.Text) End If ' 退出应用程序 If sender.Equals(btnExit) Then System.Windows.Application.Current.Shutdown() End If End Sub Private Sub nextPage_Return(ByVal sender As Object, _ ByVal args As BooleanReturnEventArgs) Handles _ nextPage.Return ' 显示后一个窗体中输入的字符串 returnString.Text = "From Page 3: " & args.Result.ToString End Sub End Class |
<BooleanPageFunction x:Class="Page3" xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" > <DockPanel> <StackPanel DockPanel.Dock="Left" Background="LightBlue"> <TextBlock Margin="10,10,10,10"> Page 3</TextBlock> </StackPanel> <StackPanel DockPanel.Dock="Right" Background="LightYellow"> <TextBlock Margin="10,10,10,10"> Single?</TextBlock> <RadioButtonList Margin="10,10,10,10"> <RadioButton Name="rbTrue">True</RadioButton> <RadioButton Name="rbFalse">False </RadioButton> </RadioButtonList> <DockPanel> <Button DockPanel.Dock="Left" Click="ButtonClick" Name="btnPreviousPage" Margin="10,10,10,10" Width="80" HorizontalAlignment="Left"> Previous Page</Button> </DockPanel> <Button Click="ButtonClick" Name="btnExit" Margin="10,10,10,10" Width="80" HorizontalAlignment="Left">Exit</Button> </StackPanel> </DockPanel> </BooleanPageFunction> |
图13:Page3.xaml。这个应用程序的最后一个页面,它询问一个简单的布尔型值并返回第二个页面。 |
Partial Public Class Page3 Inherits BooleanPageFunction ' 用于保存页面中选择的状态 Private Shared _Status As Boolean ' 示例事件处理程序 Private Sub OnLoaded(ByVal sender As Object, _ ByVal e As RoutedEventArgs) Handles Me.Loaded If _Status = True Then rbTrue.IsChecked = True Else rbFalse.IsChecked = True End If End Sub Private Sub ButtonClick(ByVal sender As Object, _ ByVal e As RoutedEventArgs) If sender.Equals(btnPreviousPage) Then If rbTrue.IsChecked = True Then _Status = True Else _Status = False End If OnFinish(_Status) End If ' 退出应用程序 If sender.Equals(btnExit) Then System.Windows.Application.Current.Shutdown() End If End Sub End Class |
图14:应用程序流程。这个线性应用程序的三个页面按页面1、2、3的次序进行,按相反的次序返回。 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者