Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement IDataErrorInfo on string indexers databinding?

With xaml (notice the binding on dictionary entry Attributes[Welcome]):

    <Grid x:Name="LayoutRoot">
        <StackPanel>
            <TextBlock FontSize="36"
                   FontWeight="Bold"
                   Foreground="Purple"
                   Text="{Binding Attributes[Welcome]}"
                   VerticalAlignment="Center"
                   HorizontalAlignment="Center"
                   TextWrapping="Wrap" />
            <TextBox Text="{Binding Attributes[Welcome],Mode=TwoWay, ValidatesOnDataErrors=True}"></TextBox>
            <TextBox Text="{Binding Attributes[Welcome],Mode=TwoWay, ValidatesOnDataErrors=True}"></TextBox>
            <TextBox Text="{Binding Test, Mode=TwoWay, ValidatesOnDataErrors=True}"></TextBox>
            <TextBox Text="{Binding Test, Mode=TwoWay, ValidatesOnDataErrors=True}"></TextBox>
        </StackPanel>
    </Grid>
When the view model implements IDataErrorInfo as:

        public string Error
        {
            get { return ""; }
        }

        public string this[string columnName]
        {
            get { 
                return "Compulsory Error"; 
            }
        }


Only columnName == "Test" is ever passed. And therefore I get the following application: enter image description here
How can I validate the values being set for the Attributes Dictionary?

like image 284
basarat Avatar asked Nov 13 '22 23:11

basarat


1 Answers

I figured that I needed to implement IDataErrorInfo on the Dictionary rather than the viewmodel containing the dictionary. But since IDataErrorInfo member's conflict with IDicitonary. I ended up implementing INotifyDataErrorInfo.

like image 96
basarat Avatar answered Dec 30 '22 22:12

basarat