不使用 DataContext 绑定命令 [silverlight+prism]

发布于 2024-09-08 04:35:57 字数 290 浏览 1 评论 0原文

您好,我在将命令绑定到数据网格内的按钮时遇到问题。

这里应该有解释,但并不能解释一切。

http://msdn.microsoft.com/en-us/library/dd458928。 aspx

命名空间基础结构中的类中应该包含什么?

有人可以向我展示一个使用它的基本示例吗? 不仅仅是代码的一部分......

Hello I have a problem with binding commands to button inside datagrid.

Here should be explanation but it doesn't explain everything.

http://msdn.microsoft.com/en-us/library/dd458928.aspx

What should be in classes in namespace Infrastructure?

Can somebody show me a really basic sample of using this?
not just parts of the code...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风蛊 2024-09-15 04:35:57

Prism 命令快速入门 - 包含在 Prism drop 中,应该提供您正在寻找的简单代码示例。

除非另有指定,否则所有数据绑定都会违反当前的 DataContext。 DataContext 沿控件树继承,除非控件专门选择 DataContext。

例如,您的 Button 可能如下所示,并且会在 DataContext 具有的任何内容上查找 SaveCommand:

<Button Command="{Binding SaveCommand} />

如果您想绑定到类代码隐藏中公开的命令,您的按钮也可能如下所示:

<UserControl x:Name="UserControl">
   ...
    <Button Command="{Binding SaveCommand, ElementName=UserControl}"
   ...
</UserControl>

使用 DelegateCommand 只是一种方法实现您绑定的 ICommand,并且应该在 Prism QuickStart 中可见。

The Prism Commanding QuickStart - included with the Prism drop should provide the simple code example you are looking for.

All data-bindings go against the current DataContext unless specified otherwise. The DataContext is inherited down the tree of controls unless a control specifically picks a DataContext.

For example your Button might look like this and would look for the SaveCommand on whatever the DataContext has:

<Button Command="{Binding SaveCommand} />

Your button could also look like this if you wanted to bind to a command exposed on your classes code-behind:

<UserControl x:Name="UserControl">
   ...
    <Button Command="{Binding SaveCommand, ElementName=UserControl}"
   ...
</UserControl>

Using DelegateCommand is just a way of implementing the ICommand you bind to and that should be visibile in the Prism QuickStart.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文