ZoHen
ZoHen

Reputation: 11

MultiValueConverter reading from ObservablleCollection

I am working on a wpf mvvm project. In a user control I have a datagridControl from Devexpress that is bound to data from a Observable collection.

     <xcdg:DataGridControl x:Name="DataGridName"   HorizontalAlignment="left" VerticalAlignment="Stretch"
                                AutoCreateColumns="False"  
                                ItemsSource="{Binding ViewModel.Items}" 
                                ItemScrollingBehavior="Immediate"  SynchronizeCurrent="True" TabIndex="69" >

    <xcdg:DataGridControl.Columns >
        <xcdg:Column FieldName="Name" AllowSort="False"  Title="Name"   ShowInColumnChooser="False" />
    </xcdg:DataGridControl.Columns>
</xcdg:DataGridControl>

The class in the Observable collection Contains a Name (string) and IsVerified (Boolean).

 private ObservableCollection<myData> _items = new ObservableCollection<myData>();

  public ObservableCollection<myData> Items
    {
        get { return _items; }
        set { _items = value; }
    }

     public class myData
     {
        public string Name { get; set; }

        public bool IsVerfied { get; set; }
     }

I also have a textblock that I use to display an error message above the dataGrid when the Value of IsVerfied is false.

 <TextBlock Name="textBlockErrrMessage" Foreground="IndianRed">
                            <TextBlock.Text>
                                <MultiBinding Converter="{StaticResource MultiValueConverter}">
                                    <Binding Path="DataContext.IsVerified" RelativeSource="{RelativeSource AncestorType=xcdg:DataRow}" ElementName="DataGridName" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>

To do this I plan on having a multivalueconverter (I am also doing the same thing but for a different control so that is why I choose a MultiValueConverter) that I would like to send the IsVerfied value from the Collection and return the message. My issue is how do I set the Binding in the MultiBinding to read the IsVerfied value from the Observablecollection. This particular line is what I believe is the issue in locating the Collection value

<Binding 
    Path="DataContext.IsVerified" 
    RelativeSource="{RelativeSource AncestorType=xcdg:DataRow}" 
    ElementName="DataGridName" />

Upvotes: 1

Views: 76

Answers (1)

Tim Oehler
Tim Oehler

Reputation: 109

In your Binding, you want to use either RelativeSource or ElementName, but not both. See this post for a good clarification on the differences between the two.

Upvotes: 1

Related Questions