页面只能将Window或Frame作为父级

时间:2015-07-11 14:52:13

标签: wpf vb.net

我只想在WPF页面之间切换,但得到上面提到的错误:Page只能将Window或Frame作为父级。 这是我的代码

Imports System.Windows.Forms

Public Class Page1

Private Sub btn1_Click(sender As Object, e As RoutedEventArgs) Handles btn1.Click
    Try

        Dim dd As New Page2


        Me.Content = dd
        Me.txt1.Text = (dd.txt10.Text)
    Catch ex As Exception

        txt1.Text = ex.Message
    End Try

xaml文件代码

<Page x:Class="Page2"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  mc:Ignorable="d" 
  d:DesignHeight="300" d:DesignWidth="300"
  Title="Page2">
<Grid>

    <Button x:Name="button1" Content="Button" HorizontalAlignment="Left" Margin="163,62,0,0" VerticalAlignment="Top" Width="101" Height="55"/>
    <TextBox x:Name="txt10" HorizontalAlignment="Left" Height="23" Margin="38,81,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>

</Grid>

请指导我做错了什么?

1 个答案:

答案 0 :(得分:3)

根据名称Page1,我认为它是一个页面。在Page1中放置一个Frame并将Page2加载到Frame中。