[英]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:
尝试这个:
<TextBox x:Name="MyTextBox" Text="Hello" />
<Button Click="Button_Click" />
void Button_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(InfoPage), MyTextBox.Text);
}
<TextBlock x:Name="MyTextBlock" />
protected override void OnNavigatedTo(NavigationEventArgs e)
{
MyTextBlock.Text = e.Parameter?.ToString();
}
That will do it. 那样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.