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.

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”

The future of Windows Presentation Foundation (WPF) and what’s coming next

In 2006 I started working with the first preview versions of the Windows Presentation Foundation with my Trivadis fellow Christoph Pletz. We wrote 2007 the very first German article about MVVM and 2008 I published my first book with the title “Windows Presentation Foundation – the ultimate handbook”.

Continue reading “The future of Windows Presentation Foundation (WPF) and what’s coming next”

Microsoft TechDays 2013 Basel

Thanks to all who joined my sessions at TechDays in Basel. Also a big thanks to Microsoft Switzerland for organizing this great and successful event. I really enjoyed the two days of networking with awesome people.

Please find the slides and demos of my talks on my homepage by selecting the talk:

http://www.thomasclaudiushuber.com/talks.php

If you were not able to attend TechDays in Basel, you can just watch my talks here (they’re in German. Find other talks on on channel9):

 

Feel free to ask any questions about the topics by commenting here or just send me an email.

Thomas

Received Microsoft MVP award 2013

Wow, on 1st of July I’ve received my very first Microsoft MVP (Most Valuable Professional) award. I received it in the area “Client Development”.

MVP_FullColor_ForScreen

Thanks to all the people out there in the .NET/C#/XAML-community, thanks to all the readers of my books, articles and blog-posts, thanks to the participants of my public talks, thanks to the colleagues at Trivadis and thanks to Microsoft Switzerland for their great support. In the end I want to thank my family and all the friends and people supporting me in any technical and non-technical way. You’re awesome!

More about the MVP award you can read on
http://mvp.microsoft.com/

My personal MVP profile is here:
http://mvp.microsoft.com/en-us/mvp/Thomas%20Claudius%20Huber-5000162

Keep on codin’
Thomas