这个窗口间传值,我到底错在哪了?头疼
wpf吧
全部回复
仅看楼主
level 5
小e毅 楼主
主窗口
public partial class MainWindow : Window
{
public string title { get; set; }
public string nei { get; set; }
public MainWindow()
{
InitializeComponent();
}
private void btnyes_Click(object sender, RoutedEventArgs e)
{
MyWindow mywin = new MyWindow();
title = txttitle.Text;
nei = txtnei.Text;
mywin.ShowDialog ();
}
}
}
子窗口
public partial class MyWindow : Window
{
public MyWindow()
{
InitializeComponent();
}
private void mywin_Loaded(object sender, RoutedEventArgs e)
{
MainWindow maiwin = new MainWindow ();
Title = maiwin.title ;
txtnr.Text = maiwin.nei;
}
}
}
目的是: 传txttitle.Text为子窗 标题
txtnei.Text为子窗文本内容
求大神帮忙啊,脑子都看炸了[不公平]
2013年11月24日 13点11分 1
level 11
你这根本就没传递吧?就算你用控件传值,也应该是(子窗体.控件名.属性)
而不是在子窗体里搞什么实例化父窗体,就算你要在子窗体里获取,也应该是(app.current.已经运行的窗体列表)
2013年11月24日 23点11分 3
我还没学到传值、那个传递过程我也觉得不靠谱、帮我改改呗[乖]
2013年11月25日 01点11分
level 6
手机码字不方便,明天码给你。
2013年11月30日 16点11分 4
谢谢你~我看了一个例子、现在会了
2013年11月30日 16点11分
回复 小e毅 :Ok
2013年12月01日 03点12分
level 7
public partial class MainWindow : Window
{
public string title { get; set; }
public string nei { get; set; }
public MainWindow()
{
InitializeComponent();
}
private void btnyes_Click(object sender, RoutedEventArgs e)
{
MyWindow mywin = new MyWindow();
title = txttitle.Text;
nei = txtnei.Text;
mywin.ParentWin=this;
mywin.ShowDialog ();
}
}
}
子窗口
public partial class MyWindow : Window
{
public MyWindow()
{
InitializeComponent();
}
public Window ParentWin{get;set;}
private void mywin_Loaded(object sender, RoutedEventArgs e)
{
//MainWindow maiwin = new MainWindow ();
//Title = maiwin.title ;
//txtnr.Text = maiwin.nei;
if(ParentWin!=null)
{
Title = ParentWin.title ;
txtnr.Text = ParentWin.nei;
}
}
}
}
2013年12月19日 08点12分 5
level 5
霍霍
2013年12月29日 09点12分 6
level 12
在子窗体里设属性变量,然后在主窗体赋值
2013年12月30日 01点12分 7
level 11
AK大神为何含泪退役?M4大师为何退居二线?狙击大手为何欲哭无泪?神器94为何重现江湖?刀战达人为何被马来捅了菊花?警家为何烟雾连连?队友乱扔闪究竟是敌是友?ACE为何频繁被踢?高手为何被队友坑死?游戏语音为何传来阵阵童声?网吧键盘V、F11俩键为何被摁坏?服务器为何越来越卡?挑战第30关为何无故被踢?巨人城17关为何有人乱跑?泰坦为何惨死街头?挑战频道为何全天爆满?游戏骂人之风为何愈演愈烈? 单键魄狙为何退出江湖?CF为何呈现低龄化趋势?家长兜内现金为何不翼而飞?老马腰包为何越来越鼓?麒麟大手为何被认做爹娘?BUG里的一抹倩影究竟是人是鬼?连环被灭队案又有着什么不可告人的秘密?这一切究竟是人性的扭曲还是道德的沦丧?是教育的缺失还是现实的无奈?敬请收看ccav12《小学生上线了》
2013年12月30日 18点12分 8
level 5
这根本就没传值,这中回传值需要用委托的,在一窗口定义事件,在主窗口调用,回传子窗口的值
2014年03月26日 15点03分 9
1