简体   繁体   中英

cannot use multibinding in RadGridView

I'm having serious difficulties with grid's combobox column binding.

I have a grid in which each row represent an item. My item has the property "NumberPhase" .

I want to bind the ItemsSource of a certain combobox column. 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 ). 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 . 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). 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:

A 'MultiBinding' cannot be set on the 'ItemsSourceBinding' property of type 'GridViewComboBoxColumn'. A 'MultiBinding' can only be set on a DependencyProperty of a DependencyObject.

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. 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)

  <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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