如何从单击按钮的框架中的页面检索数据 C#
How to retrieve data from a page in a frame on button click c#
private void btnEdit(object sender, RoutedEventArgs e)
{
}
在此按钮事件中,我希望能够从显示在此 window 框架中的不同 xaml 检索两个变量。我不知道该怎么做
我有一个带有两个按钮和一个框架的主屏幕。在此框架中,我显示一个页面。单击上面代码中的此按钮时,我希望能够从页面上的页面文本块中获取两个变量。我该怎么做?
我基本上需要从帧中收集数据以用于此事件
我不知道你的项目结构和你想做什么。所以我会在我理解的基础上给你举个例子。
我创建了以下页面。页面名称是 "TestPage.xaml"
<Page x:Class="WhosebugAnswers.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:WhosebugAnswers"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="TestPage">
<Grid>
<TextBlock x:Name="textBlock"/>
</Grid>
</Page>
我创建了 MainWindow,它有两个按钮和一个框架,如下所示。
现在Frame的来源是"TestPage.xaml".
<Window x:Class="WhosebugAnswers.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:WhosebugAnswers"
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!!!";
}
通过上述方式,您可以访问(检索)页面的var。
private void btnEdit(object sender, RoutedEventArgs e)
{
}
在此按钮事件中,我希望能够从显示在此 window 框架中的不同 xaml 检索两个变量。我不知道该怎么做
我有一个带有两个按钮和一个框架的主屏幕。在此框架中,我显示一个页面。单击上面代码中的此按钮时,我希望能够从页面上的页面文本块中获取两个变量。我该怎么做?
我基本上需要从帧中收集数据以用于此事件
我不知道你的项目结构和你想做什么。所以我会在我理解的基础上给你举个例子。
我创建了以下页面。页面名称是 "TestPage.xaml"
<Page x:Class="WhosebugAnswers.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:WhosebugAnswers"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="TestPage">
<Grid>
<TextBlock x:Name="textBlock"/>
</Grid>
</Page>
我创建了 MainWindow,它有两个按钮和一个框架,如下所示。 现在Frame的来源是"TestPage.xaml".
<Window x:Class="WhosebugAnswers.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:WhosebugAnswers"
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!!!";
}
通过上述方式,您可以访问(检索)页面的var。