【问题标题】:How to pass data from WPF form to WPF usercontrol? [closed]如何将数据从 WPF 表单传递到 WPF 用户控件? [关闭]
【发布时间】:2014-12-24 11:44:39
【问题描述】:

我有 Mainwindow.xaml(它是一个表单)一些字符串传递给 UserControl1.xaml(它是一个用户控件)。

【问题讨论】:

  • 您的问题完全不清楚。你能澄清一下吗?请阅读FAQHow to Askhelp center
  • 用户控件还是其他窗口?

标签: c# wpf


【解决方案1】:

1)您可以在 UserControl 中创建公共属性,例如:

public string SomeString
{
get;
set;
}

然后通过xaml传递字符串:

<UserControl1 SomeString="String"/> 

或 将 SomeString 属性绑定到 MainWindow 中的属性

<UserControl1 SomeString="{Binding MyStr}"/>

2)您可以通过构造函数将字符串传递给 UserControl。

var uc = new UserControl(MyString);

【讨论】:

    猜你喜欢
    • 2011-01-27
    • 2013-07-23
    • 2016-06-28
    • 1970-01-01
    • 2012-12-27
    • 2016-09-08
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    相关资源
    最近更新 更多