关于WPF的两个窗口之间简单的数据传递【附源代码】
2018-02-01 14:47
477 查看
目标:将窗口1(Window1)的数据传输给窗口2(Window2)。
VS版本:2015
如下图提示建立:
建立窗体1:
建立窗体2:
VS版本:2015
如下图提示建立:
建立窗体1:
<Window x:Class="TestTxt.Window1" 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:local="clr-namespace:TestTxt" mc:Ignorable="d" Title="Window1" Height="350" Width="525"> <Grid> <TextBox x:Name="txt_Input" HorizontalAlignment="Left" Height="23" Margin="93,137,0,0" TextWrapping="Wrap" Text="{Binding Path=Id0, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="120"/> <Button x:Name="GetNum" Content="保存" HorizontalAlignment="Left" Margin="110,220,0,0" VerticalAlignment="Top" Width="75" Click="button1_Click"/> </Grid> </Window>
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.IO; using System.ComponentModel; namespace TestTxt { public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { string name = txt_Input.Text.ToString(); Window2 about = new Window2(); about.getName = name; about.ShowDialog(); } } }
建立窗体2:
<Window x:Class="TestTxt.Window2" 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:local="clr-namespace:TestTxt" mc:Ignorable="d" Title="Window2" Height="300" Width="300"> <Grid> <TextBox x:Name="txt_Output" HorizontalAlignment="Left" Height="23" Margin="129,108,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/> <Button x:Name="SetNum" Content="读取" HorizontalAlignment="Left" Margin="168,168,0,0" VerticalAlignment="Top" Width="75" Click="button2_Click"/> </Grid> </Window>
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.IO; namespace TestTxt { public partial class Window2 : Window { public string getName { get; set; }//①定义一个可读可写的公用的字符串:getName public Window2() { InitializeComponent(); } private void button2_Click(object sender, RoutedEventArgs e) { txt_Output.Text = getName; } } }
相关文章推荐
- 关于WPF的两个窗口之间简单的数据传递
- 关于WPF的两个窗口之间通过创建和读取txt传递数据【附源代码】
- wpf关于两个窗口之间的数据传输例程
- 关于window.showModalDialog 的简单应用,父子窗口之间的传递
- Android成长之路-关于bundle实现两个activity之间的数据传递
- 关于winform中,两个窗体之间传递数据
- 两个Activity之间的数据传递(使用简单的intent方法)
- 关于WPF多窗口消息传递的简单实现
- C#委托(delegate)简单示例:在两个form之间传递数据
- 关于两个窗口间的数据传递
- Android成长之路-关于bundle实现两个activity之间的数据传递
- iOS两个APP之间的数据传递和跳转
- 关于Cocos2d-x中两个场景之间参数的传递
- (转载)在C#用WM_COPYDATA消息来实现两个进程之间传递数据
- bootstrap-table实现两个表格之间数据的传递,表格添加行删除行功能
- 进程之间通讯:M_COPYDATA消息来实现两个进程之间传递数据.
- 【mui】窗口管理及窗口之间的数据传递
- Flex--主程序与弹出窗口之间传递数据
- 如果在C#用WM_COPYDATA消息来实现两个进程之间传递数据
- Android中两个Activity之间数据传递及返回