简体   繁体   English

不能在RadGridView中使用多重绑定

[英]cannot use multibinding in RadGridView

I'm having serious difficulties with grid's combobox column binding. 我在使用网格的combobox列绑定时遇到了严重的困难。

I have a grid in which each row represent an item. 我有一个grid ,其中每一行代表一个项目。 My item has the property "NumberPhase" . 我的商品的属性为"NumberPhase"

I want to bind the ItemsSource of a certain combobox column. 我想绑定某个combobox列的ItemsSource The list of values is supposed to be different for different rows. 对于不同的行,值列表应该是不同的。

When binding to my item's property only, it works fine: 仅绑定到我的商品的属性时,它可以正常工作:

<telerik:gridviewcomboboxcolumn x:name="sensorCountColumn" edittriggers="CellClick"
    width="*" itemssourcebinding="NumberPhase" datamemberbinding="{Binding FactorType, Converter={StaticResource enumDescriptionConverter}, ConverterParameter=FACTOR_TYPE}"
    isreadonlybinding="{Binding IsThreePhaseParentAndNotDeleted, Converter={StaticResource invertBooleanConverter}}"
    editorstyle="{StaticResource radComboBoxStyle}">

But, I want to add dependency in another variable (which is not of the item bounded to this grid's row ). 但是,我想在另一个变量中添加dependency项(该变量不属于此grid's row绑定的项目)。 So I tried something like this: 所以我尝试了这样的事情:

<telerik:gridviewcomboboxcolumn x:name="sensorCountColumn" edittriggers="CellClick"
    width="*" datamemberbinding="{Binding FactorType, Converter={StaticResource enumDescriptionConverter}, ConverterParameter=FACTOR_TYPE}"
    isreadonlybinding="{Binding IsThreePhaseParentAndNotDeleted, Converter={StaticResource invertBooleanConverter}}"
    editorstyle="{StaticResource radComboBoxStyle}">

    <telerik:GridViewComboBoxColumn.ItemsSource>
        <MultiBinding diagnostics:PresentationTraceSources.TraceLevel="High" Converter="{StaticResource sensorCountConverter}">
            <Binding Path="NumberPhase" />
            <Binding Path="Data.PanelConfig.ID" Source="{StaticResource editedLocation}" />
        </MultiBinding>
    </telerik:GridViewComboBoxColumn.ItemsSource>

    ...

</telerik:gridviewcomboboxcolumn>

When running that, my converter got the first value (NumberPhase) as DependencyProperty . 运行该代码时,我的转换器将第一个值(NumberPhase)作为DependencyProperty UnsetValue . UnsetValue The second value is just fine. 第二个值很好。

I thought maybe I should change the tag name to ItemsSourceBinding instead of ItemsSource (because in the first example I used that name for one variable and it worked). 我以为也许应该将标签名称更改为ItemsSourceBinding而不是ItemsSource (因为在第一个示例中,我将该名称用于一个变量,因此可以使用)。 So I tried something like this: 所以我尝试了这样的事情:

<telerik:gridviewcomboboxcolumn x:name="sensorCountColumn" edittriggers="CellClick"
    width="*" datamemberbinding="{Binding FactorType, Converter={StaticResource enumDescriptionConverter}, ConverterParameter=FACTOR_TYPE}"
    isreadonlybinding="{Binding IsThreePhaseParentAndNotDeleted, Converter={StaticResource invertBooleanConverter}}"
    editorstyle="{StaticResource radComboBoxStyle}">

<telerik:GridViewComboBoxColumn.ItemsSourceBinding>
    <MultiBinding diagnostics:PresentationTraceSources.TraceLevel="High" Converter="{StaticResource sensorCountConverter}">
        <Binding Path="NumberPhase" />
        <Binding Path="Data.PanelConfig.ID" Source="{StaticResource editedLocation}" />
    </MultiBinding>
</telerik:GridViewComboBoxColumn.ItemsSourceBinding>
</telerik:gridviewcomboboxcolumn>

The result was an exception thrown with the message: 其结果是一个exception与消息抛出:

A 'MultiBinding' cannot be set on the 'ItemsSourceBinding' property of type 'GridViewComboBoxColumn'. 不能在“ GridViewComboBoxColumn”类型的“ ItemsSourceBinding”属性上设置“ MultiBinding”。 A 'MultiBinding' can only be set on a DependencyProperty of a DependencyObject. “ MultiBinding”只能在DependencyObject的DependencyProperty上设置。

I've also read about the proxy pattern , but I think I can't use it in my case, because when I try to place it inside the grid I get the following message: 我还阅读了有关代理模式的信息 ,但是我认为我无法使用它,因为当我尝试将其放置在网格中时,会收到以下消息:

The type 'RadGridView' does not support direct content. “ RadGridView”类型不支持直接内容。 I cannot place it outside because then I'll have a problem to bind to the proper row's item of the grid. 我无法将其放置在外面,因为那样我将无法绑定到网格的正确行项目。

Any suggestion will be appreciated!! 任何建议将不胜感激!

I think this might be usefull to you: (put the multibinding inside ItemTemplate) 我认为这可能对您有用:(将Multibinding放入ItemTemplate内)

  <telerik:GridViewComboBoxColumn>
            <telerik:GridViewComboBoxColumn.ItemTemplate>
                <DataTemplate>
                    <TextBlock>
                        <TextBlock.Text>
                            <MultiBinding diagnostics:PresentationTraceSources.TraceLevel="High" Converter="{StaticResource sensorCountConverter}">
                                <Binding Path="NumberPhase" />
                                <Binding Path="Data.PanelConfig.ID" Source="{StaticResource editedLocation}" />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </telerik:GridViewComboBoxColumn.ItemTemplate>
        </telerik:GridViewComboBoxColumn>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM