Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何从点击按钮c的框架中的页面检索数据#_Wpf_User Interface_Button_Frame - Fatal编程技术网

Wpf 如何从点击按钮c的框架中的页面检索数据#

Wpf 如何从点击按钮c的框架中的页面检索数据#,wpf,user-interface,button,frame,Wpf,User Interface,Button,Frame,在这个按钮事件中,我希望能够从这个窗口框架中显示的不同xaml中检索两个变量。我不知道怎么做 我有一个带有两个按钮和一个框架的主屏幕。在这个框架中,我显示了一个页面。当点击上面代码中的这个按钮时,我希望能够从页面上的pages文本块中获取两个变量。我该怎么办 我基本上需要从要在本次活动中使用的框架中收集数据我不知道您的项目结构和您试图做什么。因此,我将在我理解的基础上向您展示一个示例 我创建了下面的页面。页面名称为“TestPage.xaml” 通过上述方法,您可以访问(检索)页面的var。这个

在这个按钮事件中,我希望能够从这个窗口框架中显示的不同xaml中检索两个变量。我不知道怎么做

我有一个带有两个按钮和一个框架的主屏幕。在这个框架中,我显示了一个页面。当点击上面代码中的这个按钮时,我希望能够从页面上的pages文本块中获取两个变量。我该怎么办


我基本上需要从要在本次活动中使用的框架中收集数据

我不知道您的项目结构和您试图做什么。因此,我将在我理解的基础上向您展示一个示例

我创建了下面的页面。页面名称为“TestPage.xaml”


通过上述方法,您可以访问(检索)页面的var。

这个问题有点抽象。你能提供更多的信息吗?@jjw我试图更好地解释一下情况。我认为这篇文章对你有帮助。如果您获得了页面的实例,那么您可以检索Page@jjw因此,一旦我这样做,它就会输出实例WpfApp3.CountdownScreen。我想这是对的?我该从哪里着手才能得到你绝对需要的答案呢。
private void btnEdit(object sender, RoutedEventArgs e)
        {
}
<Page x:Class="StackOverFlowAnswers.TestPage"
      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" 
      xmlns:local="clr-namespace:StackOverFlowAnswers"
      mc:Ignorable="d" 
      d:DesignHeight="450" d:DesignWidth="800"
      Title="TestPage">

    <Grid>
        <TextBlock x:Name="textBlock"/>
    </Grid>
</Page>
<Window x:Class="StackOverFlowAnswers.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:attached="clr-namespace:Parse.WpfControls.AttachedProperties"
        xmlns:local="clr-namespace:StackOverFlowAnswers"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <Style x:Key="ConvertableTextBox" TargetType="TextBox">
            <Setter Property="attached:CharacterConvertBehavior.ConvertEnable" Value="True"/>
        </Style>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="20"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal" Grid.Row="0">
            <Button Width="50" Margin="0 0 10 0" Click="Button_Click"/>
            <Button Width="50" Margin="0 0 10 0"/>
        </StackPanel>

        <Grid Grid.Row="1">
            <Frame x:Name="mainFrame" Source="TestPage.xaml">
            </Frame>
        </Grid>
    </Grid>
</Window>
private void Button_Click(object sender, RoutedEventArgs e)
{
    var page = (TestPage)this.mainFrame.Content;

    page.textBlock.Text = "test!!!";
}