Использование Multi Binding в Telerik Datagrid - PullRequest
2 голосов
/ 03 ноября 2011

Как передать несколько параметров в параметрах команды.

вот что я пытаюсь сделать: я хочу отправить Проверено или нет (я могу сделать это, введя логическое поле для привязанного объекта. Но я не хочу этого делать), и я хочуотправить выбранный объект данных для этой строки.

                <telerik:GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewDataControl}}, Path=DataContext.LineItemSelection}">
                            <CheckBox.CommandParameter>
                                <MultiBinding Converter="{StaticResource CommandConverter}">
                                    <Binding Path="IsChecked" />
                                    <Binding RelativeSource="{RelativeSource Self}"/>
                                </MultiBinding>
                            </CheckBox.CommandParameter>
                        </CheckBox>
                    </DataTemplate>
                </telerik:GridViewColumn.CellTemplate>

ОБНОВЛЕНИЕ:

Я добавил класс с именем selection Item.Чтобы увидеть, что получает конвертер.

    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        SelectionItem si = new SelectionItem();
        foreach (var value in values)
        {
            Type t = value.GetType();
            if (t.FullName == "System.Boolean")
                si.IsSelected = (bool) value;
            else
            {
                si.SelectedCustomer = value as Customer;
            }
        }
        return si;
    }

Тип второго параметра - сам флажок, если я использую

    <Binding RelativeSource="{RelativeSource Self}"/>

Здесь я хочу элемент данных, который связан с этимстрока (в данном случае Заказчик).Я даже пытался использовать

    <Binding RelativeSource= "{RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewColumn}}" Path="DataContext"  />

Но это также имеет значение null.почему это?

Ответы [ 2 ]

0 голосов
/ 30 ноября 2011

с использованием

<CheckBox Name="chkSelection" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewDataControl}}, Path=DataContext.LineItemSelection}">
    <CheckBox.CommandParameter>
        <MultiBinding Converter="{StaticResource CommandConverter}">
            <Binding Path="IsChecked" ElementName="chkSelection" />
            <Binding />
        </MultiBinding>
    </CheckBox.CommandParameter>
</CheckBox>

сделал трюк

0 голосов
/ 28 ноября 2011

Попробуйте простую привязку, передав текущий источник привязки преобразователя, затем приведите к базовому объекту и на основе IsChecked верните значение.

<DataTemplate>
      <CheckBox Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewDataControl}}, Path=DataContext.LineItemSelection}">
         <CheckBox.CommandParameter>
               <MultiBinding Converter="{StaticResource CommandConverter}">
                     <Binding Path="IsChecked" />
                     <Binding RelativeSource="{RelativeSource Self}"/>
                </MultiBinding>
         </CheckBox.CommandParameter>
       </CheckBox>
</DataTemplate>
 // CommandConverter should simply return the values
 public object Convert(...)
 {
     return values;
 }

Теперь в обработчике команд вы можете получить доступ к параметрам:

public void OnLineItemSelection(object parameter)
{
    object[] parameters = (object[])parameter;
    bool isChecked = (double)parameters[0];
    var instance = (TYPENAME)parameters[1];
}
...