WPF XAML Visibility binding with property value comparison

WPF XAML Visibility binding with property value comparison

Following on from my previous articles about ‘Passing multiple parameters to an ICommand in WPF’ and ‘Speeding up large WPF ComboBoxes’ the application stack I am currently working on has provided another article on a WPF subject!

The ability to show or hide UI elements based on criteria related to other elements is nothing new; only showing an ‘Other Details’ text box when a drop-down value of ‘Other’ is selected is the bread and butter of many end-user applications. There are a number of ways of doing this in the WPF/XAML/MVVM world, the default is often the use of a property on the ViewModel relating to the visibility (or enabled state) of the UI element in question, and this is how I have been implementing it until now!

The most recent set of screens I have been working on are a lot more complicated than other parts of the application (lots of business logic fields which depend on the values of other fields). Adding lots and lots of ‘IsEnabled’ or ‘IsVisible’ properties (along with their backing fields, and INotifyProperyChanged code) seemed very messy to me, and I felt there must be a better solution. I already use an IValueConverter to convert simple boolean values (FirstNameIsVisible for example) into WPF Visibility values, so I thought I could take that one step further and perform comparisons.

Read more

Speeding up large WPF ComboBoxes

Speeding up large WPF ComboBoxes

The WPF application I am working on at the moment contains a questionnaire definition system; the user interface for which contains a number of ComboBoxes (drop-down lists). The nature of the application means that some of these ComboBoxes contain a large number of dynamic entries (not hardcoded, they change based on user actions).

I have found that WPF ComboBoxes with a large number of entries; particularly ones which have overridden ToString methods, can take a second or two to ‘drop down’ (display). This is because WPF renders the entire dropdown interface when it opens; this means if you have many entries in the list each one will be rendered regardless of its position in the list. If you have custom logic inside the ToString methods this can present a significant overhead on the UI thread.

Read more

Serving a single page with a Cloudflare Worker

Serving a single page with a Cloudflare Worker

Ok, so I may have gone overboard on the dot dev domains, obviously, I purchased melodious.dev and forwarded it to this website but I also purchased two random domains:

I could have just forwarded these domains to melodiouscode.net, but on my lunch break, I decided to chuck some single page sites at them for giggles. I, however, did not want to spend any more money than I already do on domain-related things. In steps Cloudflare workers.

For those that do not know about workers; they are small chunks of javascript that you can run on the “edge” of Cloudflare. This means that you can execute code at the moment that a page is requested from your site. In the case of my serverless approach, the code executes before the page request has the chance to realise there is no web server!

Read more

Passing multiple parameters to an ICommand in WPF

Passing multiple parameters to an ICommand in WPF

The project I am currently working on is a sizable line-of-business desktop program written using the WPF framework; a framework I particularly like working with due to its extensibility and ease of design (via XAML).
One of the powerful parts of WPF is the ICommand system for binding buttons to ViewModel methods; I won’t go into the details of it here as it deserves an article of its own. However one of its basic functions is the ability to pass a parameter from the UI back to the ViewModel’s ICommand property, such as the selected item in a data table.

The application I am currently working on has lots of nested UI components, and some of the button events need to pass back multiple parameters (something I had not done before). It seems that it is perfectly possible to pass more than one parameter from the XAML View up to the ViewModel.
The XAML is simple, you nest a MultiValueConverter inside your buttons CommandParameter element; you also need to provide a reference to an IMultiValueConverter (which you can define statically in a resource elsewhere in your application).

Read more