CommunityToolkit / MVVM-Samples

Sample repo for MVVM package
Other
1.11k stars 222 forks source link

Questions about ObservableValidator in MVVM Toolkit Sample App #108

Open JesseLiberty opened 1 year ago

JesseLiberty commented 1 year ago

In the MVVM Toolkit Sample App there is a sample of the ObservableValidator. I have a couple questions (thank you in advance for reading through all this)  

public ValidationFormWidgetViewModel(IDialogService dialogService)
{
     DialogService = dialogService;
}

  I assume the IDialogService is being passed in via DI - is that correct? Is this the preferred way to invoke a dialog from the VM?   There is this declaration:   public event EventHandler? FormSubmissionCompleted;   Later, if there are no errors it is invoked with:   FormSubmissionCompleted?.Invoke(this, EventArgs.Empty);   Can you explain that construct? It does not show what gets called when you invoke that. The XAML on the other hand has   

<Grid>
        <muxc:InfoBar
            x:Name="SuccessInfoBar"
            Title="Success"
            Message="The form was filled in correctly."
            Severity="Success">
            <interactivity:Interaction.Behaviors>
                <interactions:EventTriggerBehavior EventName="FormSubmissionCompleted" SourceObject="{x:Bind ViewModel}">
                    <interactions:ChangePropertyAction
                        PropertyName="IsOpen"
                        TargetObject="{x:Bind SuccessInfoBar}"
                        Value="True" />
                    <interactions:ChangePropertyAction
                        PropertyName="IsOpen"
                        TargetObject="{x:Bind FailureInfoBar}"
                        Value="False" />
                </interactions:EventTriggerBehavior>
            </interactivity:Interaction.Behaviors>
        </muxc:InfoBar>

  So I'm guessing that when FormSubmissionCompleted is invoked it tiggers the display of the SuccessInfoBar??   Is EventTriggerBehavior documented anywhere? I can't find it.   Also what is with this construct:    TargetObject="{x:Bind SuccessInfoBar}"   Is that the (new?) (preferred?) way of handling a binding?

Unfortunately the namespaces are not shown as far as I can tell. Is there a complete sample that has the complete contents of all the files for ObservableValidator?

Thanks!