In my XAML, I get all clients by binding the 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 invokes the model to retrieve the entire collection of clients:
public class CustomersViewModel { public ObservableCollection<Customer> GetAll { get { try { return Customer.GetAll; } catch (Exception ex) { throw new Exception(ex.Message); } } } }
If something goes wrong in the model (poorly formed XML file, etc.), then the exception bubbles up to the full GetAll property in the ViewModel.
First question: I was surprised that XAML does not seem to do anything with the exception and just continues and does not display anything. Is it for design? Is this part of the “untied approach”?
Second question: It makes me think that I could somehow handle the exception in XAML , for example
Pseudocode:
<Trigger> <Trigger.OnException> <TextBox Text="The customer data could not be loaded."/> </Trigger.OnException> </Trigger>
Is something like the above code possible?
source share