In my XAML I get all customers by binding to a GetAll property:
<ListBox ItemsSource="{Binding GetAll}"
ItemTemplate="{StaticResource allCustomersDataTemplate}"
Style="{StaticResource allCustomersListBox}">
</ListBox>
The GetAll property is an observable collection in my view model, which calls the Model to get all collection of customers:
public class CustomersViewModel
{
public ObservableCollection<Customer> GetAll {
get
{
try
{
return Customer.GetAll;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}
If anything goes wrong in the model (badly formed XML file, etc.) then an exception bubbles up all the way to that GetAll property in the ViewModel.
First Question: I was surprised that XAML doesn't seem to do anything with the exception and just goes ahead and displays nothing. Is this by design? Is this part of the "decoupling approach"?
Second Question: This leads me to think I could handle the exception in XAML somehow, such as
Pseudo Code:
<Trigger>
<Trigger.OnException>
<TextBox Text="The customer data could not be loaded."/>
</Trigger.OnException>
</Trigger>
Is something like the above code possible?