yashao1987 2015-03-30 06:50 采纳率: 0%
浏览 4117

WPF的Mainwindow和Usercontrol之间的传值

我用的是ModernWindow框架,现在就是在MordernWindow定义了一个按钮和一个标签,在点击按钮的时候总是回到一个主界面,在UserControl切换的时候,可以让标签改变值,要怎么做啊

  • 写回答

1条回答

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-10-27 15:56
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:
    • 建议你看下这篇博客👉 :WPF 用户控件(UserControl)
    • 除此之外, 这篇博客: WPF 用户控件(UserControl)中的 窗体引用用户控件 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:
      <Window x:Class="WpfDemo.UserControlDemo.UseUserControlWindow"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:userControlDemo="clr-namespace:WpfDemo.UserControlDemo"
              mc:Ignorable="d"
              Title="UseUserControlWindow" Height="600" Width="400">
          <Grid>
              <Grid.RowDefinitions>
                  <RowDefinition Height="0.2*"></RowDefinition>
                  <RowDefinition Height="*"></RowDefinition>
                  <RowDefinition Height="0.2*"></RowDefinition>
                  <RowDefinition Height="*"></RowDefinition>
              </Grid.RowDefinitions>
              <Label Content="使用OwnUserControl用户控件"></Label>
              <userControlDemo:OwnUserControl Grid.Row="1"></userControlDemo:OwnUserControl>
              <Label Grid.Row="2" Content="使用UseUserControlUserControl用户控件"></Label>
              <userControlDemo:UseUserControlUserControl Grid.Row="3"></userControlDemo:UseUserControlUserControl>
          </Grid>
      </Window>
      

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler