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

子窗体

<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

相关文章:

  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
  • 2021-09-25
  • 2021-10-12
猜你喜欢
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-06-18
  • 2021-11-04
相关资源
相似解决方案