Category Archives

Releasing MVVM Light V5.3 to Nuget

.NET, MVVM, Work, Xamarin, XAML
9 Comments

With Xamarin Evolve coming up (I am currently on the way to Orlando!), it was time to release a new version and take care of a few bugs, improvements and new features.

Update: To be clear I didn’t remove the Windows 8.1 version, it is still available! Only the Windows 8 version is removed.

In version 5.3, the majority of the activity was on the data binding system for Xamarin.iOS and Xamarin.Android, with many improvements in stability and performance, as well as a few new features. Existing code will continue to work as is, and at most you might have a few “deprecated” warnings, which will give you time to update your code. I also added 3 classes and a few helpers around them, which should help you greatly when you work with lists: ObservableRecyclerAdapter (for Android RecyclerView), ObservableTableViewSource (for iOS TableView) and ObservableCollectionViewSource (for iOS CollectionView). These objects will be detailed in separate blog posts.

In other areas not directly Xamarin-related, you will also find quite a few bug fixes. Here is list of changes. You will also find a few explanations below. I will publish additional blog posts with more details about the Observable list components mentioned above.

Removed old frameworks

In a desire of simplification, I removed the Silverlight 4, Windows Phone 7.1 and Windows 8 versions of MVVM Light from the repo. This does NOT affect the Silverlight 5, Windows Phone 8.0 and 8.1, Windows 8.1 as well as Windows 10 of course which are still very well supported. The main reason for not supporting these older versions is that they require Visual Studio 2012 and cannot be maintained or tested in VS2015. I hope that this doesn’t affect your projects too much. Should that be the case, please send me a note. We can always find a solution!

Fixing Nuget install.ps1 and documentation

There was a silly bug in the install.ps1 script that is run after the Nuget installation is performed, it is fixed now. Also, I added a more explicit description of the packages mvvmlight and mvvmlightlibs, in order to underline the differences between both.

Documentation: Closures not supported

In the same vein, I added explicit documentation warning that closures are not supported in the Messenger Register method, as well as in the RelayCommand Execute and CanExecute delegates. This is sometimes an issue. The reason is that these components are using WeakReference to avoid tight coupling with the objects using them. When we store the delegate that will be executed by the Messenger or respectively the RelayCommand, we store them as WeakAction instances. This causes the delegate to be “dehydrated” and stored as a MethodInfo. When we “rehydrate” the delegate, we notice that the closure has been lost, and the call fails. I am experimenting with ways to work around that limitation (i.e storing the delegates are actual Action or Func and not dehydrating them, which will of course cause a strong coupling to occur… but would be acceptable in some cases if the developer explicitly opts into this). For the moment, closures are not supported and the developer needs to find another way, for example storing the parameter in an attribute or a list of some kind.

ViewModelBase

I optimized the code a bit there and made it less redundant. I also made the RaisePropertyChanged methods public (was: protected) following a user’s request. This can make sense in certain scenarios when an external object wants to call this method on another VM.

NavigationService

Here too I fixed some bugs. I also added new features for iOS:

  • Navigating with an unconfigured key in iOS: In iOS, the key passed to the NavigateTo method is often the same value as the corresponding Storyboard ID set in the Storyboard designer for a given controller. Until V5.3, you had to configure the key for the NavigationService, which was often leading to code such as
    Nav.Configure(“SecondPage”, “SecondPage”);
    this didn’t quite make sense. As of V5.3, if you call NavigateTo with a key that is not configured, we will attempt to find a corresponding controller with this same Storyboard ID. Of course if you want to use a different ID, you can still configure the navigation service like before.
  • Retrieving parameter without deriving from ControllerBase: Until now, the implementation used to retrieve a navigation parameter from the NavigationService forced you to derive your controller from ControllerBase. That was annoying, especially in cases where you had to derive from another base class anyway. I removed this restriction. Instead, you can now retrieve the NavigationService from the ServiceLocator in the ViewDidLoad method, and then call the GetAndRemoveParameter method to get the navigation parameter (if there is one). This is the same method than in the Android NavigationService.

Binding system

I fixed a few bugs here which were causing the data binding to fail in certain scenarios. I also added a lot of unit tests to test current and new features (currently about 300 unit tests which run in both iOS and Android), as well as a few features. Expect samples very soon!

  • FallbackValue: This value can be set in the SetBinding method (or in the Binding constructor) and will be used in case an error occurs when the Binding is being resolved. This can happen, for example, if you have a complex path expression and one of the elements is null, which would cause a NullReferenceException to happen inside the Binding. This exception is caught and nothing happens in the application, but the FallbackValue will be used as the Binding value if the user has set it. This can be used for information purposes. For example, if your source property is MyViewModel.SelectedItem.Name, and nothing is selected, the SelectedItem is null and the FallbackValue (for instance “Nothing selected yet”) is used.
  • TargetNullValue: This value can also be set in the SetBinding method (or in the Binding constructor) and will be used in case the Binding value is null. This can also be used for information purposes.
  • SetCommand with static parameter: I added an overload to the SetCommand extension method which can be used to pass a static parameter to the ICommand’s Execute and CanExecute methods. Prior to V5.3, you had to define a binding for this (and use the SetCommand(…, Binding) method) which was very cumbersome in case the binding value never changed. Now you can use the SetCommand method with a simple value (or if you want to observe the value you can still use the SetCommand method with a binding).
  • SetCommand for ICommand: In previous versions, you could only use SetCommand with a RelayCommand (or RelayCommand<T>), which was an oversight. Now I modified this method to work with any ICommand.
  • New name for UpdateSourceTrigger: This method is now named ObserveSourceEvent. The old method is still available but marked as deprecated. The old name was confusing for users.
  • New name for UpdateTargetTrigger: Similarly, this method is now named ObserveTargetEvent. The old method is still available but marked as deprecated.
  • Binding with implicit event names: When you set a binding on a UI element in Android and iOS, you must also specify which event should be observed for changes. This is necessary because properties in these elements, unlike in Windows, aren’t depedency properties. For instance, you can choose between FocusChange or TextChanged for an EditText, etc. In the huge majority of cases however, the same event is used over and over for a given element.
    On Android, the TextChanged event is used for an EditText and the CheckedChange event for CheckBox; on iOS, the ValueChanged event is used for UISwitch, the Changed event for UITextView, and the EditingChanged for UITextField. Note that existing code does not need to be changed unless of course you want to simplify it. And like before, you can continue to use ObserveSourceEvent and ObserveTargetEvent (formerly UpdateSourceTrigger and UpdateTargetTrigger) to specify a different event if needed.
  • SetCommand with implicit event names: Like with the Binding class, when we set a Command on a control, we specify which event must be observed to trigger the command. For commonly used controls, this is mostly the same event. To simplify the code, you don’t have to explicitly specify these events anymore. The events that are observed implicitly are: On Android the Click event for Button, and the CheckedChange event for CheckBox. On iOS, the TouchUpInside event for UIButton, the Clicked event for UIBarButtonItem and the ValueChanged event for UISwitch. Of course you can also continue to specify these events explicitly, or any other event you wish to observe instead.
  • Binding to private fields and local variables: In previous versions, you could only set a binding on public properties (for example public MainViewModel Vm, or public CheckBox MyCheck; in V5.3, you can also set bindings on objects which are saved as private attributes. You can even create a new Binding (using the Binding constructor instead of the SetBinding method) on elements which are defined as local variables.
  • Binding on RecyclerView, TableViewSource and CollectionViewSource cells: The feature above (binding on local variables) can be useful, for example to create a new binding between a data item and the cell that represents it in a list control. I’ll have blog posts for RecyclerView, TableViewSource and CollectionViewSource.

As you can see, this is a massive change set and I am really happy that your excellent feedback has led to these improvements. Of course the task is not over and there is more coming. V5.3 should greatly improve working with data binding in MVVM Light, in Xamarin.iOS and Xamarin.Android. As always, keep your feedback coming!

For more information about data binding in Xamarin.iOS and Xamarin.Android, you can watch my Xamarin Evolve 2016 session (slides, sample code and video recording will be posted ASAP).

Happy coding!
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook
 

Enabling / Disabling design data in Visual Studio 2015 Update 1

.NET, Blend, MVVM, Technical stuff, Universal Windows Platform UWP, Visual Studio, Work, XAML
No Comments

If like me you use design time data in Blend or the Visual Studio designer, you may have noticed a small change that is actually very convenient, but maybe not the most discoverable feature ever: You can now switch design time data on or off very easily!

To illustrate this, follow the steps:

  • Start Visual Studio 2015 Update 1.
  • (if you have not done so already) Install MVVM Light with: Tools / Extensions and Updates / Online –> Search for mvvm light and install the extension.
  • After restarting Visual Studio, select File / New Project and create a new MvvmLight (Win10Univ) application. This will create a new Windows 10 Universal project with all the MVVM Light scaffolding.
  • Open MainPage.xaml in the Visual Studio designer (or select Design in Blend from the context menu on MainPage.xaml).
  • Make sure that you set the configuration manager to x86 (not ARM or x64).
  • Build the application.

At this point, you will see one of two images below:

2016-02-29_14-10-21

Figure 1: Design data is enabled

 2016-02-29_14-10-48

Figure 2: Design data is disabled

What’s the difference?

If you study both figures closely, you will see the difference at the bottom: Figure 1 shows actual data created in the code of the MVVM Light application (“Welcome to MVVM Light [design]” and the “Starting…” label for the Clock), while figure 2 shows the names of the databound properties (WelcomeTitle and Clock) instead. Switching from one figure to the other is done by using a new button on the design surface, which is a little hard to find. Here is an illustration:

2016-02-29_14-16-09

This small button is tooltipped “Enable Project Code”.

What this button does is enable or disable a feature that MVVM Light applications are taking advantage of: The possibility to run some of your app code while the application is loaded in the visual designer. If the button is toggled on, the design time code will be enabled, which explains why the WelcomeTitle label shows the design time text, and the Clock shows the initialization text. This is useful, because it will allow you to design your app visually without having to actually run it, and so you will be faster.

On the other hand however, design time code can crash the visual designer. This type of errors can be fixed by updating the design time data, but they are time consuming, and sometimes it is just not worth it. In those cases, you may want to disable the design time code for the current view, which can be done by toggling the small button off.

In the case where the button is disabled, you can still edit the UI somehow, because the name of the property will be shown, and you can at least set the font, font size, foreground color  etc, which is better than nothing. For lists, this works too: If the design time code is enabled, the design time elements will be shown like in figure 3. On the other hand, if you disable the design time code, three “dummy” items will be created, which allows you to edit the item template visually. Here is an example taken from an app I am currently working on.

 2016-02-29_17-30-17

In addition, it also enables some level of design work with configurations that were not initially supported by the visual designer: ARM and x64. You can verify this by changing the configuration in the MVVM Light application above. Here the toggle button becomes disabled, and the view in figure 2 is displayed.

Having the possibility to disable design time code renders the visual designer more stable by allowing the user to eliminate possible design time error from the equation, and to still use the designer even if the design time code fails. It also allows some level of designer usage even with ARM or x64 configurations. This should accelerate things especially towards the end of the project, when maintaining the design time data can be time consuming.

Happy coding
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook
 

Ten!

IdentityMine, MVVM, Work, XAML
1 Comment
Update (10 Jan 2016) I added Techorama to the list of my talks. Hope to see many of you in Belgium!!

It’s been a tradition for me to look in my inbox for an email from the Microsoft MVP award team on January first… this year is special because it is the tenth time that I am getting the award. I am really happy and excited about this milestone, and it’s a great occasion to reflect on a decade of community work with Microsoft frameworks and tools. Getting awarded 10 times in a row is a huge honor and I feel blessed and honored.

mvpbanner

The community work

I have always been active in the community, from my very first involvements with code, starting with many contributions to the early JavaScript community (these were the days of Usenet and the comp.lang.javascript newsgroup, and I started contributing around 1997 probably). These were exciting days because we were pretty much inventing everything, before the early days of frameworks. The very first framework we started to discuss was a horrible thing called Prototype which was making everything way too complicated. JQuery came only quite a lot later. In fact, much of what is discussed these days in the so-called SPA (Single page application) space is either stuff that we had already talked about in the newsgroup, or building on top of it. Always funny to hear again about these topics after so many years.

Professionally, I started using my JavaScript (and HTML and CSS) skills when we started an ASP.NET project around 2002, which took about 3 years to complete. Before that, most of my involvement with JavaScript had been on private time. It was an exciting time with (a) digging deeper into the .NET ecosystem (I had started using .NET with V1.0 in 2001) and (b) using my web skills for money :) It was a great project, and we innovated in many areas, using a lot of AJAX (before it was cool) and other user experience improvements.

2016-01-03_15-32-54

After this project ended, about 11 years ago, I was extremely lucky to be sent to Las Vegas for MIX06 and discovered XAML… The awesome atmosphere at MIX totally pumped me up and led me to start blogging and exploring WPF for a project we were starting. One year later, someone noticed my little blog and decided it was good enough for my first MVP award… The same year Microsoft recommended IdentityMine to us for a WPF training, and I discovered this incredible team of developers and designers (and PMs!) whom I now call my friends, and this amazing place, PNW which feels like my second home…

It was a wild ride for sure. My explorations led me to make friends with a lot of developers within and outside of Microsoft, get very involved with the development of some awesome products like XAML and Blend, to get into the conference circuit, to write two books, to create the MVVM Light Toolkit and manage its growth, to start working with Xamarin (and get awarded an MVP there too), to get accepted in the Microsoft Regional Directors program, and more… And now I feel ready for 10 more years (and quite a few more, in fact :)

2016, public appearances and travel

At the moment I have a few conferences lining up, and a few more that I hope to confirm later on. For now here is what I know:

2016-01-03_19-23-41

I will speak at TechDays Switzerland 2016 in Baden. This is exciting because it is a rebirth of the TechDays conference here, which had disappeared in the past few years. I always love TechDays as a concept. This year we will have a half day of keynotes on February 29 and one day of breakout sessions on March 1st.

2016-01-03_19-26-31

I will attend the Build conference in San Francisco from March 30 to April 1st. This should be an interesting event where we might not see huge announcements but rather see a stabilization and consolidation of Windows 10 and all associated technologies. I like these years where we have a chance to dig deeper in technology, and to polish and refine our devices and frameworks.

2016-01-03_19-25-58

On April 24th to 28th, I will be in Orlando FL at Xamarin Evolve. I am really excited about this opportunity to dive deep into MVVM Light for Xamarin, and specifically the databinding framework. I was very impressed by Evolve 2014 which was my first appearance at this event. It felt almost like the MIX conferences of yore, and a great place to meet a lot of interesting people in this space.

techorama

On May 3 and 4, I cannot wait to go back to Belgium for Techorama. I will be talking about Windows Presentation Foundation 4.6 and show you what’s new. Yes WPF is still important, and is widely used for desktop applications, especially in enterprise and industry. WPF was my first XAML love, and I cannot wait to share some of that love with you all!

2016-01-03_19-25-29

On May 26th-27th, I will be at DevSum in Stockholm Sweden. First time at this smaller conference but I heard so many great thing about it that I am impatient to try it out. Thanks Tibi for having me :)

That’s what is confirmed for now. There is a little more being discussed at the moment, and I will announce it when the time comes. As always, I am really proud and happy to have a chance to talk to an audience about the topics that excite me, and to have the possibility to meet and chat with many of you face to face.

Happy coding!
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook
 

Solving the issue where unexpected languages appear when you submit to the Windows 10 Store (#mvvmlight)

MVVM, Technical stuff, Universal Windows Platform UWP, Windows 10, Work
No Comments

Ah the joy of developing for new platforms :)

Over the past few weeks, I received a few bug reports where an application that was supporting only one, non en-US language was receiving some errors when being submitted to the store. In short, the store thought that the application was bi-lingual (original language + en-US) and asked for all the assets (description etc) in en-US as well. Needless to say it is no fun for the developer who has to prepare all the assets in en-US at the last minute.

This issue was described here in the CommonServiceLocator library. And unfortunately, because MVVM Light has a dependency on this library, it can also occur in MVVM Light applications too.

It’s a bug!

After reporting the issue to Microsoft, and having one member of the team spend some time on it (thanks!), it so happens that it is due to a bug in Visual Studio 2015. This is a regression in the handling of portable class libraries. And what’s great is that (while waiting for the bug to be fixed), there is a workaround:

  • Open your application’s CSPROJ file in a text editor.
  • In the first PropertyGroup of the project, add the following line:
<SkipIntermediatePriGenerationForResourceFiles>false</SkipIntermediatePriGenerationForResourceFiles>

This line will prevent the bug from happening, and you should be able to submit your app to the store as usual.

Happy coding!
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)

Share on Facebook
 

One million downloads!

MVVM, Technical stuff, Work, Xamarin, XAML
13 Comments

Logo MVVM Win8 Purple 103x80

I am not sure exactly when it happened but as I was reviewing the MVVM Light Toolkit’s download numbers, I suddenly realized that we are now over a MILLION downloads.

The breakdown of the downloads is as follows:

TOTAL: 1’130’704 downloads

Read the rest of this entry »

Source code and samples for the ADC15 talks

ADC, HoloLens, MVVM, Technical stuff, Windows 10, Work, Xamarin
2 Comments

I just published the material for last Monday’s Advanced Developer Conference in Frankenthal Germany.

Read the rest of this entry »

Upcoming speaking engagements and travels!

.NET, IdentityMine, MVVM, Technical stuff, Visual Studio, Windows 10, Work, WPF, Xamarin, XAML
1 Comment

Wow it’s autumn already! When did that happen? The Summer was very busy, with a lot of super interesting work at IdentityMine, the release of MVVM Light V5.2, and preparation for an upcoming article in MSDN Magazine (more about that later) and even some work on some personal apps I wanted to port to Windows 10 and improve.

In the coming few weeks, I have some travel coming up, with speaking engagements. Here is the list below, and I will update it if something new comes up. I really hope to have a chance to see you at one of these talks, and if you do come, please come say hi and let’s chat!

Read the rest of this entry »

MVVM Light V5.2 is live!

.NET, Blend, MVVM, Technical stuff, Universal Windows Platform UWP, Windows 10, Xamarin, XAML
17 Comments

This week I published MVVM Light V5.2 to Nuget and to the Visual Studio Gallery.

There are a few highlights which are described as always in the Change Log. See further below for a more detailed explanation of some of the changes.

Read the rest of this entry »

Using compiled bindings (x:Bind) with #mvvmlight

Build, MVVM, Technical stuff, Universal Windows Platform UWP, Windows 10, Work, XAML
7 Comments

One of the XAML-related announcements at Build this year was the availability of compiled bindings. These new bindings can be used instead of the “classic” {Binding} syntax in XAML. Note that this syntax is only available in Windows 10 universal applications, not in WPF yet.

The advantage of compiled bindings over normal bindings is that (wait for it) they are compiled. So there is syntax check by the compiler when you build your project. Also, the bindings will be resolved much faster because they do not rely on reflection during runtime.

Read the rest of this entry »

#Techorama 2015: Slides and source code are online!

MicrosoftBand, MVVM, Technical stuff, Techorama, Work, Xamarin
No Comments

Techorama was a real pleasure. I have to admit I was a bit tired from all the travel (I had just come back from 2 weeks in the US a couple of days before flying to Brussels) but I was super happy to go because I know how well organized this conference is. They love their speakers, and we love them back.

Read the rest of this entry »