WPF 用户控制 XAML 命令
我有一个带有两个按钮的 3.5 WPF 用户控件,我希望能够通过用户控件的 xaml 将命令绑定到这些按钮。
x:Usercontrol x:Name:fou Button1Command="{Binding StuffCommandHandler}" Button2Command="{Binding Stuff2CommandHandler}"
问题是上述绑定不起作用。 如何通过 xaml 将命令绑定到用户控件的按钮(其中两个)?
我在 UserControl 的代码后面得到了这个,并将 Button1CommandHandler 绑定到 Button1.Command
private ICommand _button1Command;
public ICommand Button1CommandHandler
{
get { return _button1Command; }
set { _button1Command = value; }
}
I've got a 3.5 WPF User Control with two buttons and I'd like to be able to bind commands to these buttons via the User Control's xaml.
x:Usercontrol x:Name:fou Button1Command="{Binding StuffCommandHandler}" Button2Command="{Binding Stuff2CommandHandler}"
Problem is the above bindings are not working.
How can I bind commands to the User control's buttons, two of them, via xaml?
I've got this in the UserControl's code behind and I bind Button1CommandHandler to Button1.Command
private ICommand _button1Command;
public ICommand Button1CommandHandler
{
get { return _button1Command; }
set { _button1Command = value; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将
Button1CommandHandler
设为依赖属性:然后将按钮的
Command
绑定到它。如果您从代码创建按钮,则可以像这样绑定它:You have to make
Button1CommandHandler
into a dependency property:and then bind your button's
Command
to it. If you create the button from code, you can bind it like this: