简体   繁体   English

Windows商店应用程序WInRT XAML C# - 如何获取导航的页面文本框值

[英]Windows store app WInRT XAML C# - How to get navigated page textbox value

Windows store app WInRT XAML C# - How to get navigated page textbox value.here is my all code................................................... Windows商店应用程序WInRT XAML C# - 如何获取导航的页面文本框值。这是我的所有代码.............................. .....................

1.MainPage.xaml 1.MainPage.xaml

    <Button Content="Navigate" Name="nav" HorizontalAlignment="Left" Margin="826,198,0,0" VerticalAlignment="Top" Click="nav_Click"/>
    <TextBlock HorizontalAlignment="Left" Margin="402,201,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="27" Width="155"/>
    <Frame Name="framee"  VerticalAlignment="Top" Height="440" HorizontalAlignment="Left" Width="600" Margin="402,238,0,0"/>
    <Button Content="Get" Name="get" HorizontalAlignment="Left" Margin="1062,193,0,0" VerticalAlignment="Top" Click="get_Click"/>

2.InfoPage.xaml 2.InfoPage.xaml

<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Name="Name" VerticalAlignment="Top" Margin="0,6,0,0" Width="348"/>
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Name="Address" VerticalAlignment="Top" Margin="0,43,0,0" Width="348"/>
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Name="Phone" VerticalAlignment="Top" Margin="0,80,0,0" Width="348"/>

MainPage.cs MainPage.cs

 private void nav_Click(object sender, RoutedEventArgs e)
    {
        framee.Navigate(typeof(InfoPage));
    }

    private void get_Click(object sender, RoutedEventArgs e)
    {
      here textbox name are not showing
    }

There are several ways to achieve what you're asking for. 有几种方法可以实现您的要求。 If you are using an MVVM pattern (which I personally highly recommend) then you simply need to bind the TextBox.Text to a field in the ViewModel and do the same to the same ViewModel in the MainPage... (and this could be discussed deeper so let me know if this is what you're doing.) If you're not using the MVVM pattern then you probably have no idea what I'm talking about so let's look at other options. 如果您正在使用MVVM模式(我个人强烈推荐),那么您只需将TextBox.Text绑定到ViewModel中的一个字段,并对MainPage中的相同ViewModel执行相同操作...(这可以讨论更深层,所以让我知道这是你正在做什么。)如果你没有使用MVVM模式,那么你可能不知道我在说什么,所以让我们看看其他选项。

Another possible solution is to Interface the new pages requiring them all to have the same interface that in turns exposes the TextBox.Text property or a TextBox with the same name or however you decide. 另一种可能的解决方案是将需要它们的新页面连接起来,使其具有相同的界面,从而暴露TextBox.Text属性或具有相同名称的TextBox,或者您决定。 This is a big deeper as it may rely on other internal features such as Dependency Injection and or Controllers depending on how you're setup. 这是一个更深层次,因为它可能依赖于其他内部功能,如依赖注入和/或控制器,具体取决于您的设置方式。

If you still have no idea what I'm talking about then I'm going to assume you're semi new at all of this and suggest you simply look for the TextBox via different approaches. 如果你仍然不知道我在说什么,那么我将假设你是半新的,建议你只是通过不同的方法寻找TextBox。 It would be much easier to answer the question directly if you provided the full code and XAML for both pages at least. 如果您至少为两个页面提供了完整代码和XAML,那么直接回答问题要容易得多。

Simple enough question. 简单问题。 Try this: 尝试这个:

MainPage.xaml MainPage.xaml中

<TextBox x:Name="MyTextBox" Text="Hello" />
<Button Click="Button_Click" />

MainPage.xaml.cs MainPage.xaml.cs中

void Button_Click(object sender, RoutedEventArgs e)
{
    Frame.Navigate(typeof(InfoPage), MyTextBox.Text);
}

InfoPage.xaml InfoPage.xaml

<TextBlock x:Name="MyTextBlock" />

InfoPage.xaml.cs InfoPage.xaml.cs

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    MyTextBlock.Text = e.Parameter?.ToString();
}

That will do it. 那样做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows Store App XAML-如何获取导航页面的文本框值 - Windows Store App XAML - How to get textbox value of navigated page 如何将文本框的文本获取到另一个 xaml 中的文本块? c# windows store app - How to get the text of textbox to textblock in another xaml? c# windows store app C#XAML Windows应用商店中带有文本框的InputDialog / MessageDialog - InputDialog/MessageDialog with a textbox in C# XAML Windows store app 如何在Windows Store应用程序中使用WinRT C ++中的“字节数组”获取结构数组? - How to get the array of struct with “byte array” from WinRT C++ to C# in Windows Store app? Windows应用商店-XAML C#-如何在代码中访问Page.Resource - Windows Store App - XAML C# - How to access Page.Resource in code 如何在Windows 8应用商店应用(C#/ XAML)中正确添加图像 - How to properly add image in Windows 8 store app (C#/XAML) C#Xaml如何获取列表框所选项目的文本框值 - C# Xaml How to get listbox selected item textbox value 从Windows Store App C#WinRT拨打电话 - Make telephone call from Windows Store App C# WinRT 清除WinRT Windows Store App C#中WebView的导航历史记录 - Clear the navigation history of WebView in WinRT Windows Store App C# WinRT ListView,将itemsource作为列表 <KeyValuePair<string, string> &gt;错误XAML(Windows 8.1通用应用程序(XAML / C#)) - WinRT ListView with itemsource as List<KeyValuePair<string, string>> error XAML (Windows 8.1 Universal App (XAML/C#))
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM