Blog

Race condition when using a Binding on a DoubleAnimation inside of a Storyboard

Nice example of a race condition on MSDN Forums, because the Binding is running on a different thread and won’t update in time. Let’s look at the problem:

There’s this Storyboard in the MainWindow to animate the Rectangle with the name “rectangle”:

In the codebehind-File the Storyboard is started in the rectangle_MouseDown-handler by calling the Begin-method on it:

The DurationConverter returns a Duration of one Minute:

When you click on the Rectangle, you’ll see that it is animated with the default duration of 1 second instead of using the duration of 1 minute. When you add breakpoint in the Convert-method of the DurationConverter, you’ll see that the Convert-method is called after the call to the Begin-method of the Storyboard. So it’s too late to grab the wanted Duration.

How can you solve it? Just use a little trick to delay the call of the Begin-method on the Storyboard by one millisecond. This will do it:

Open ComboBox from ViewModel in MVVM-scenario

On the Microsoft MSDN-Forums there was a question how to open up a Combobox in an MVVM-scenario from the ViewModel.

To do this, you use the typical MVVM way: You define a bool-Property in the ViewModel to control the DropDown. Here I named it IsDropDownOpen:

Note that I’m using a ViewModelBase-class in the snippet above. That ViewModelBase-class defines the OnPropertyChanged-method to raise the PropertyChanged-event:

Now let’s assign the MainViewModel to the MainWindow’s DataContext:

Now in XAML I can bind the ComboBox’ IsDropDownOpen-Property to the IsDropDownOpen-Property of the MainViewModel that is in the DataContext. In addition I bound a Checkbox to the IsDropDownOpen-Property of the MainViewModel to be able to change the value of that property:

That’s it. When I check the CheckBox, the Dropdown-List opens. Instead of changing the IsDropDownOpen-Property of the MainViewModel with a CheckBox, you could also set the IsDropDownOpen-Property in the MainViewModel when for example a Command is executed.

UWP: The Master-Detail-Problem with the events SelectionChanged & LostFocus and How to Fix it

While creating apps with the Universal Windows Platform (UWP) I noticed a weird behavior, but I’m not sure if it’s a bug. Let’s just call it the “Master-Detail-Problem”.

To explain it, I stripped  down my code to the XAML-snippet below. No code-behind needed. Continue reading “UWP: The Master-Detail-Problem with the events SelectionChanged & LostFocus and How to Fix it”

Developer Week 2016 – it was great

Last week I was at the developer week conference in Germany / Nürnberg. It was a great conference with fantastic people and great sessions.

I gave two talks:

  • S.O.L.I.D.-principles for C# Developers
  • Test Driven Development and MVVM: How to write testable ViewModels

Continue reading “Developer Week 2016 – it was great”

Calling the Azure Event Hub REST-API – from UWP, WPF and any other .NET (Core) Client

To push events into Azure Event Hub you can use the Nuget-package WindowsAzure.ServiceBus (https://www.nuget.org/packages/WindowsAzure.ServiceBus/). That package works pretty straight forward, but there’s one problem:

Continue reading “Calling the Azure Event Hub REST-API – from UWP, WPF and any other .NET (Core) Client”

Render just the first line of a TextBlock

Sometimes you want a TextBlock to just display one line. For example if you have a huge virtualized ListView that contains many data items and in the DataTemplate you’re using a TextBlock. When the TextBlock has different height, the virtualization leads to some not so nice behavior when scrolling: Continue reading “Render just the first line of a TextBlock”

Creating a background application with WPF

Sometimes you need to have an application running in the background. Then you don’t want your MainWindow to be visible all the time. Instead you just want to have an icon in the notification area that allows the user to open up the MainWindow and to exit the application. In WPF you can do this easily with the help of Windows Forms’ NotifyIcon-class.

Continue reading “Creating a background application with WPF”

Solved: Lenovo, the Clickpad/Ultranav and the missing hardware-buttons (W540 / T540 / W541)

In several models like W540/T540 etc. Lenovo has replaced the hardware-buttons for the Trackpoint with a big Touchpad. It looks like this:

Continue reading “Solved: Lenovo, the Clickpad/Ultranav and the missing hardware-buttons (W540 / T540 / W541)”