Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all articles
Browse latest Browse all 1760

New Post: Manually Triggering Validation in WPF while using Caliburn Micro

$
0
0
I have a view model that implements IDataErrorInfo (and derived from Caliburn Micro's Screen class) like this
public class MyViewModel : Screen, IDataErrorInfo
{
    ...

    public BindableCollection<MyEntity> Entities { get; set; }

    public MyEntity SelectedEntity
    {
        get { return _entity; }

        set
        {
            _entity = value;
            OnSelectedEntityChanged();
        }
    }

    private void OnSelectedEntityChanged()
    {
        // implementation
    }

    public virtual string Error
    {
        get { // implementation }
    }

    public virtual string this[string columnName]
    {
        get { // implementation }
    }

    public void Populating(PopulatingEventArgs e)
    {
        // implementation
    }
}
It is bound to the following XAML using Caliburn Micro (only relevant portion shown)
<tk:AutoCompleteBox 
        x:Name="Entities"
        cal:Message.Attach="[Event Populating] = [Populating($eventArgs)]"    
        SelectedItem="{Binding Path=SelectedEntity, Mode=TwoWay}"  
        HorizontalAlignment="Stretch" 
        FilterMode="None"
        IsTextCompletionEnabled="True" 
        Text="{Binding SearchText}"
        ValueMemberPath="Name">
        <tk:AutoCompleteBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Name}"></TextBlock> 
            </DataTemplate>                            
        </tk:AutoCompleteBox.ItemTemplate>                          
    </tk:AutoCompleteBox>
The problem I am running into is that when I update the SelectedEntity property programmatically, it does not cause validation to be triggered. I've tried out many different possible solution such as trying to get the binding expression and calling ValidateWithoutUpdate() on it, adding triggers in the XAML that should cause validation to be triggered etc, but none has worked so far.

How can I trigger validation that would eventually call IDataErrorInfo.Error?

Thanks!

Viewing all articles
Browse latest Browse all 1760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>