c# - Can I handle thrown exceptions in XAML? -
In my XML I receive all clients by getting them from GetAll property:
& Lt; List Box ItemsSource = "{Binding Getaway}" item template = "{static resource all clients data template}" style = "{static resource allarslistbox}" & gt; & Lt; / ListBox & gt; GetAll property is an observational collection in my visual model, which tells the model to get all the collections of customers:
public class customerviews Model {public supervision qualification & lt; Customers & gt; GetAll {Get {Try {Customer Customer.GetAll; } Hold (exception before) {new exception (ex. Message); }}} Anything goes wrong in the model (badly created XML file, etc.), then Exception bubbles for GetAll property in ViewModel
The first question: I was surprised that XAM does not appear to do anything with the exception and just goes ahead and does not show anything What is this design? Is this part of "Decoupling Approach"?
Second question: I think that I can control the exception in XAM , like
Phony Code:
& lt; Trigger & gt; & Lt; Trigger.OnException & gt; & Lt; Text box text = "Customer data could not be loaded." / & Gt; & Lt; /Trigger.OnException> & Lt; / Catalyst & gt; Is the above code possible? First of all, I imagine that it is not intended that XAML exceptions should be caught. Looking at the developer needing to fix their XML code, they are more in the form of a device, although they must be in the runtime due to the dynamic nature of XML markup
by saying this You can easily control the XAML exception by wrapping it by calling InitializeComponents within the manufacturer of your Windows class. You can either get all exceptions or especially XamlParseException , whichever you get, Epipriate.
Example:
Public Partial Segment Window 1: System Windows.Window {Public Window 1 () {try {InitializeComponent ()}} Hold (Exception Pre) {/ / Log error (including InnerExceptions!) // handle exception}}}
Comments
Post a Comment