WPF绑定:添加按钮未绑定场网格 [英] WPF Binding : Add Button to Unbound Field in grid

查看:137
本文介绍了WPF绑定:添加按钮未绑定场网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个按钮XamData presenter添加到绑定字段。

I am trying to add a button to an unbound field in XamDataPresenter.

下面是按钮的模板:

        <Style x:Key="CancelButtonTemplate" TargetType="{x:Type igDP:CellValuePresenter}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                        <Button x:Name="CancelButton" Content="Cancel" Command="{Binding CancelButtonCommand}" Width="80" Height="20" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

这是XamData presenter未绑定字段:

And here is the unbound field in XamDataPresenter:

                    <igDP:UnboundField Name="CancelOrder" Label="Cancel Order" Column="11">
                        <igDP:UnboundField.Settings>
                            <igDP:FieldSettings CellValuePresenterStyle="{StaticResource CancelButtonTemplate}" CellHeight="12" CellWidth="50">
                            </igDP:FieldSettings>
                        </igDP:UnboundField.Settings>
                    </igDP:UnboundField>                       
                </igDP:FieldLayout.Fields>   

在CancelButtonCommand的按钮,势必是在视图模型公共财产,我已经验证它的工作原理与XamData presenter之外,没有一个模板的按钮。

The "CancelButtonCommand" that the button is bound to is a public property in the viewmodel and i have verified that it works with a button outside the XamDataPresenter and without a template.

按钮显示在格,但是没有任何反应,当我preSS它。

The button shows up in the grid but nothing happens when i press it.

我究竟做错了什么?

推荐答案

我相信你需要一点点添加到您的风格结合。尝试改变这样:

I believe you need to add a little to your binding in the style. Try changing to this:

<Button Command="{Binding DataContext.CancelButtonCommand, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}"
                                CommandParameter="{Binding}">

您使用XamData presenter或XamDataGrid?如果presenter,改变上述X:​​类型为XamData presenter代替XamDataGrid

Are you using XamDataPresenter or XamDataGrid? if presenter, change the above x:Type to XamDataPresenter instead of XamDataGrid

另外:如果我还记得,我不得不添加的CommandParameter因此命令就知道在采取行动哪一行,我需要的SelectedItem的方法内。否则,每个按钮将充当完全相同。就我而言,每一个按钮应该做些什么来排它在的对象。

Also:If i remember, I had to add the CommandParameter so the command would know which row to act upon, and i needed SelectedItem inside that method. Otherwise, every button would act exactly the same. In my case, each button is supposed to do something to the object of the row it was in.

这篇关于WPF绑定:添加按钮未绑定场网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆