8,756
社区成员




<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>
private void formtest_Click(object sender, RoutedEventArgs e) { FormChildWin formChildwin = new FormChildWin(); formChildwin.Show(); }
<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>
private void OKButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void formtest_Click(object sender, RoutedEventArgs e)
{
FormChildWin formChildwin = new FormChildWin();
formChildwin.Show();
formChildwin.Closed+=new EventHandler(formChildwin_Closed);//注册关闭事件。
}
void formChildwin_Closed(object sender, EventArgs e)
{
ChildWindow childWindow = sender as ChildWindow;
if (childWindow!= null)
{
TextBox text= childWindow.FindName("myTextBox") as TextBox;//要TextBox在 ChildWindow里面的的x:Name属性来查找
if (text != null)
{
formtest.Content = text.Text;
}
}
}
private void formtest_Click(object sender, RoutedEventArgs e)
{
FormChildWin formChildwin = new FormChildWin();
formChildwin.Show();
formChildwin.Closed += new EventHandler(formChildwin_Closed);
}
void formChildwin_Closed(object sender, EventArgs e)
{
string outputText = (sender as FormChildWin).kaisei.Text;
}