sliverlight页面传值的问题

markdandan 2010-04-12 04:10:19
我有一个usercontrol的页面,在这个页面上当点击一个按钮的时候弹出controls:ChildWindow的页面,在childwindow上有一个textbox,我想在usercontrol上取得这个textbox中的值,请问有什么办法吗,谢谢!!!
Usercontrol页面的xaml

<UserControl x:Class="SilverlightApplicationStudy.OutForm.FormApplication"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Horizontal">
<Button x:Name="formtest" Content="OutPutForm" Width="100" Height="30"
Background="DarkViolet" Click="formtest_Click" FontSize="14"></Button>
</StackPanel>
</Grid>
</UserControl>

Usercontrol页面的xaml.cs

private void formtest_Click(object sender, RoutedEventArgs e)
{
FormChildWin formChildwin = new FormChildWin();
formChildwin.Show();

}


childwindow上的xaml

<controls:ChildWindow x:Class="SilverlightApplicationStudy.OutForm.FormChildWin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Title="FormChildWin"
Width="400" Height="300">
<stackPanel>
<TextBox x:Name="kaisei" Text="2010年12月25日" Width="200" Height="20" TextAlignment="Left"
Foreground="DeepPink"></TextBox>
<Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="0" />
<Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="0" />
</stackPanel>



请问当点击childwindow上的OKButton的时候(这时候会返回上一Usercontrol页面),在返回之后,我怎样得到textbox的值?
...全文
124 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
TimDavid 2010-04-13
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 markleilei 的回复:]

引用 4 楼 timdavid 的回复:

简单!
在ChildWindow的关闭事件,这个在Usercontrol页面的xaml.cs里面定义一个子窗口关闭事件委托。
C# code

private void formtest_Click(object sender, RoutedEventArgs e)
{
FormChildWin formChildwin = new F……
[/Quote]
TextBox textBoxOfChildWindow= sender as TextBox;
这个要换成
ChildWindow childWindow= sender as ChildWindow;
这里不应该是TextBox,明显事件源始一个ChildWindow;
之后再利用FineName();就可以了。
markdandan 2010-04-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 timdavid 的回复:]

简单!
在ChildWindow的关闭事件,这个在Usercontrol页面的xaml.cs里面定义一个子窗口关闭事件委托。
C# code

private void formtest_Click(object sender, RoutedEventArgs e)
{
FormChildWin formChildwin = new FormChil……
[/Quote]

这样取到的textBoxOfChildWindow是空的啊
TimDavid 2010-04-12
  • 打赏
  • 举报
回复
还想问楼主一下,如果你把你的子窗口改成ShowDialog()模式的话,上面4#(4楼的)的代码可以运行吗?
我试过把子窗口改成ShowDialog()有模式的时候,上面的代码就不行了。可能是窗口关闭了,对象给GC回收了。
那我们换种新的思维试试。
1.这里应该可以用Session的,你在子窗口Loaded事件里的的时候将TextBox保存session,之后再窗口关闭的时候从session里面读出来。(我没写程序证明,理论上时可以。应为Silverlight是hosting【宿主】在HTML页面,这里有session,只是这里Silverlight只在一个页面而已。)
2.这里也可以把值保存在App里面的。(这个绝对可以。我以前试过。但项目一大。很容易导致性能很慢。)如果这个不懂得话,自己去找先Silverlight的App对象吧。

希望这些能帮到你。
wzp144650 2010-04-12
  • 打赏
  • 举报
回复
[Quote=引用楼主 markleilei 的回复:]
我有一个usercontrol的页面,在这个页面上当点击一个按钮的时候弹出controls:ChildWindow的页面,在childwindow上有一个textbox,我想在usercontrol上取得这个textbox中的值,请问有什么办法吗,谢谢!!!
Usercontrol页面的xaml
HTML code

<UserControl x:Class="SilverlightAppl……
[/Quote]

写成属性不就可以访问了

客户端可以禁止独立存储!
TimDavid 2010-04-12
  • 打赏
  • 举报
回复
简单!
在ChildWindow的关闭事件,这个在Usercontrol页面的xaml.cs里面定义一个子窗口关闭事件委托。

private void formtest_Click(object sender, RoutedEventArgs e)
{
FormChildWin formChildwin = new FormChildWin();
formChildwin.Show();
formChildwin.Closed += new EventHandler(formChildwin_Closed);

}
private void formChildwin_Closed(object sender, EventArgs e)
{
TextBox textBoxOfChildWindow= sender as TextBox;
if(textBoxOfChildWindow!=null)
{
string text=texBoxOfChildWindow.kaisei.Text;
}
}

CosmoKey 2010-04-12
  • 打赏
  • 举报
回复
class A
{
string BB;
}

A a = new A(){BB="dd");
FormChildWin.DataContext=a;

<TextBox x:Name="kaisei" Text="2010年12月25日" Width="200" Height="20" TextAlignment="Left" Text="{Binding BB}" Foreground="DeepPink"></TextBox>

上面就可以传递内容了
来自http://www.cnblogs.com/homezzm/archive/2009/11/27/1611737.html

sliverlight没发现Session

但可以使用sliverlight的独立存储
markdandan 2010-04-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ruanwei1987 的回复:]

Session 不行 吗??
[/Quote]

sliverlight有Session???
ruanwei1987 2010-04-12
  • 打赏
  • 举报
回复
Session 不行 吗??

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧