WPF revalidate the object on any property change [Answered]

AAntonC10/13/2022
<DataGridTemplateColumn Header="Has Owner">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox
                local:Properties.Focus="True"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                IsChecked="{Binding HasOwner, Mode=TwoWay, ValidatesOnDataErrors=True}"
                />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
    
<DataGridTemplateColumn Header="Owner First Name">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBox
                local:Properties.Focus="True"
                Text="{Binding Owner_FirstName, Mode=TwoWay, ValidatesOnDataErrors=True}"
                IsEnabled="{Binding HasOwner}"
                Validation.ErrorTemplate="{StaticResource validationTemplate}"
                />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
8
AAntonC10/13/2022
Say, one of my properties depends on another property.
For example, the first name should only be validated if we have an owner, and once the owner is toggled, the first name should be revalidated, to show errors if there are any.
AAntonC10/13/2022
How do I acheieve that?
AAntonC10/13/2022
I'm not even asking about creating a graph of what property depends on what other property, what I want is simply a way to revalidate the whole data source once anything changes
AAntonC10/13/2022
Right now I'm using IDataErrorInfo for validation, but the indexer is not called when a property changes
AAntonC10/13/2022
I made a custom extension, feels ok
AAntonC10/13/2022
[MarkupExtensionReturnType(typeof(Binding))]
public class ReactiveBinding : MarkupExtension
{
    public string Path { get; set; }
    public string StringFormat { get; set; }

    public ReactiveBinding(string path)
    {
        Path = path;

    }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return new Binding(Path)
        {
            Mode = BindingMode.TwoWay,
            ValidatesOnDataErrors = true,
            UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
            StringFormat = StringFormat,
        };
    }
}
AAntonC10/13/2022
Of course, for it to be 100% compatible, you'd need to mirror all of the properties
AAntonC10/13/2022
You can't inherit from the binding one, can you?
AAccord10/19/2022
✅ This post has been marked as answered!