Skip to content

子窗体、主窗体传参

L edited this page Dec 31, 2017 · 3 revisions

在主窗体里面操纵子窗体的控件

子窗体

<Label x:Name="DialogLabel"></Label>

主窗体

<Grid>
	<Grid.RowDefinitions>
		<RowDefinition Height="*"></RowDefinition>
		<RowDefinition Height="*"></RowDefinition>
	</Grid.RowDefinitions>
	<TextBox Margin="20" x:Name="InputTextBox"></TextBox>
	<Button Margin="20" Grid.Row="1" Content="打开弹窗" Click="OpenDialog"></Button>
</Grid>

主窗体点击事件操作

private void OpenDialog(object sender, RoutedEventArgs e)
{
	Dialog dialog = new Dialog();
        //在主窗体里面操纵子窗体的控件
	dialog.DialogLabel.Content = InputTextBox.Text;
	dialog.ShowDialog();
}

直接在主窗体里面操纵子窗体的控件,进行一系列操作,业务逻辑也放在主窗体

示例代码

https://github.com/zLulus/NotePractice/tree/dev3/WPF/WpfDemo/StartWindowAndDialog

Clone this wiki locally