3

So I have a view, containing a telerik RadGridView, this view is bound to several items, but importantly I need to bind the visibility of an item in one column, to 2 items.

The converter will correctly evaluate the visility, however I need to pass back the previousProc, (currently handled) and also "This" which is a proc as well, just that row.

    <telerik:RadGridView Name="ProcedureGrid"
                         DockPanel.Dock="Left"
                         SelectionMode="Single"
                         SelectionUnit="FullRow"
                         ItemsSource="{Binding Procedures}"
                         IsReadOnly="True"
                         AutoGenerateColumns="False"
                         ShowGroupPanel="False"
                         ShowColumnHeaders="False"  
                         CanUserReorderColumns ="False"
                         RowIndicatorVisibility="Collapsed"
                         Visibility="Collapsed"
                         Width="200"
                         FontSize="18"
                         SelectionChanged="ProcedureGrid_SelectionChanged"
                         >
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn Header="Name"
                                        AllowDrop="False"
                                        DataMemberBinding="{Binding Converter={StaticResource langConverter}}"
                                        IsGroupable="False" 
                                        IsFilterable="False"
                                        MaxWidth="155"/>
            <telerik:GridViewColumn>
                <telerik:GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <nav:SmallForwardNavigateIcon MaxWidth="30" DockPanel.Dock="Right" Margin="1"
                                                      Cursor="Hand" VerticalAlignment="Center" HorizontalAlignment="Center" 
                                                      MouseDown="SmallForwardNavigateIcon_MouseDown" 
                                                      Visibility="{Binding RelativeSource={RelativeSource FindAncestor, 
                                                                                            AncestorType={x:Type UserControl}}, 
                                                                                            Path=DataContext.previousProc, 
                                                                                            Converter={StaticResource IsPrevProc}}" />
                    </DataTemplate>
                </telerik:GridViewColumn.CellTemplate>
            </telerik:GridViewColumn>
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>

can anyone see where I went wrong and what I could do to fix the xaml to pass both the previousproc and This back

asuppa
  • 571
  • 1
  • 11
  • 27
  • Since you're at the `CellTemplate` level, wouldn't that be the `DataContext`? I never used Telerik before, so this is just a guess... – code4life Feb 22 '16 at 16:07

2 Answers2

0

If I understand your UserControl host a telerik:RadGridView control.

Your UserControl has a given DataContext, which seems to conatin a property Procedures, and a property IsPrevProc.

Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.previousProc,Converter={StaticResource IsPrevProc}}" />

This code seems wrong because you write:

Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}

It means you are looking for properties in your ancestor DataContext, the one containing Procedures and IsPrevProc. So all bindings here have to be with properties of this DataContext. You can't mix in one binding call to different DataContext.

What you could do is create your "previousProc" as a property in this DataContext, so that you can call it directly.

Or you can define "IsPrevProc" as a property of the DataContext of a line of your Grid.

But you can't do both in the same binding.

Ouarzy
  • 3,015
  • 1
  • 16
  • 19
0

The ConverterParameter property is not a dependency property and hence can not be bound.

There is however an alternative solution. You could use a MultiBinding with a multi-value converter instead of a normal Binding:

<nav:SmallForwardNavigateIcon MaxWidth="30" DockPanel.Dock="Right" Margin="1"
                                                  Cursor="Hand" VerticalAlignment="Center" HorizontalAlignment="Center" 
                                                  MouseDown="SmallForwardNavigateIcon_MouseDown" 
                                                  >
    <nav:SmallForwardNavigateIcon.Visibility>
        <MultiBinding Converter="{StaticResource IsPrevProc}">
            <Binding Path="DataContext.previousProc" RelativeSource="{RelativeSource Mode=FindAncestor,
                                                 AncestorType=UserControl}"/>
            <Binding Path="DataContext.newProc" RelativeSource="{RelativeSource Mode=Self}"/>
        </MultiBinding>
    </nav:SmallForwardNavigateIcon.Visibility>
</nav:SmallForwardNavigateIcon>

Pass the new proc/this value in second binding.(use relative source if needed)

MultiValue Converter:

public class IsPrevProc : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        //Logic of new proc and Previous Proc
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
Kylo Ren
  • 8,551
  • 6
  • 41
  • 66