Category Archives

Writing, writing, writing…

.NET, Azure, Azure Functions, Cloud Developer Advocate, Microsoft, Technical stuff, Work, Xamarin
No Comments

One thing I love in my new job is that I can just sit down anywhere on Earth, grab my Surface Pro and produce content (articles, samples, etc) or learn new things just as if I was home. I just came back from Singapore and had a great time there talking at the Xamarin “MonkeyFest” conference. But it was also a busy time producing content and I am so happy that things are starting to fall into place.

Here are a few highlights:

  • I just published a few new articles (see below). As I am discovering new features of Azure, I want to share with you all. I decided to write in markdown (just like docs.microsoft.com) and publish on GitHub. Why GitHub? Well first of all this is of course the destination for developers. The markdown renderer is pretty good, it is easy and fast to create and publish good quality content. At some point this documentation might migrate to another location, but for now it makes sense to have it on Github. Also, and maybe most importantly, I like that the source code and the corresponding articles are all grouped together, for example my sample-azure-coinvalue application.
  • As I was writing, I noticed that a few topics are going to be recurrent in all my samples. So I went ahead and created the following repo: sample-azure-general. In this repo, I will document recurring processes in Azure, such as creating a trial account, Creating and testing Azure Functions in Visual Studio, Publishing functions to Azure, etc etc etc.
  • In parallel I am also working on new samples and should be able to publish more soon. So stay tuned to this blog or to my Twitter account. Yes for now the list of samples is very lean but now that everything is starting to be coherent, I want to add new content regularly!

Please help me help you!

I’d really like you all to be able to tell me what is the most important for you. And so in this spirit I want to start with two features:

Available articles:

At the moment you can find the following content in sample-azure-general:

Hopefully this is helpful to all of you, and I hope that we can get the discussion running. Microsoft is literally paying me to help you understand Azure, cross-platform, Windows, .NET and more and I love that job. So please please please don’t be shy and let me know what you need. We want to help!

Happy coding
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook

Installing #mvvmlight for .NET Standard 1.0

.NET, MVVM, Technical stuff, Universal Windows Platform UWP, WPF, Xamarin
2 Comments

I just released the new MVVM Light preview version for .NET Standard 1.0. I also published an article in the MVVM Light documentation describing the installation of the .NET Standard 1.0 version of MVVM Light as well as the changes needed to existing applications.

Hopefully you find this helpful.

This is a pre-release version and I am eager to hear your feedback. If you have any issue during the uninstallation process, installation process or while using MVVM Light for .NET Standard 1.0, send me an email at Laurent@galasoft.ch for assistance.

Happy coding!
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)

Share on Facebook

My talks in September

.NET, Azure, Azure Functions, Microsoft, MVVM, Work, Xamarin
No Comments

I don’t know about you but I had an amazing summer. I had the amazing luck of spending time in beautiful places in the Philippines, Iceland and then 2 great weeks in Seattle and Redmond. Having started to work with Microsoft on August 1st, it was great to be on campus in Redmond as a blue badge.

Apart from sitting down with my new team, meeting my new manager and old friends on campus, I also delivered two sessions at the Visual Studio Live conference. The event took place at the Microsoft conference center (Building 33) and was as packed as usual with great speakers and very competent attendees. This year was special for me because my two talks took place in the Cascade room, which is a really nice auditorium with all the comfort. I also had a lovely time interacting with attendees at the traditional Birds of a Feather lunch, where a table is assigned to a speaker and attendees can go around the room, sit down, ask questions or just chat.

You can find the slides, source code and all the information about my two talks on my website:

Amsterdam: MVVM Cross Hackfest

My next engagement is the closing event of the MVVM Cross Hackfest taking place in Amsterdam on September 2nd. The .NET Open Source foundation is sponsoring this event with others, where the aim is to encourage new contributors to help open source projects. For MVVM Cross, the event is the occasion to port this popular framework to .NET Standard. While the project lasts 2 weeks, September 2 will be the last day with a celebration, some lightning talks and a party.

At this occasion, I will speak about Azure Functions (which are really awesome). My Microsoft colleague Mike James will also be there and speak about other Azure services. The rest of the lightning talks will be held by MVVM Cross contributors. You can see the program here. My session’s abstract is the following:

Azure Functions and Xamarin

One of the most exciting recent additions to Microsoft Azure is called Functions and allows the developer to quickly build and deploy code to the cloud without complicated setup. Also dubbed “serverless computing”, Azure Functions can be triggered by timers, HTTP calls or database operations, and can communicate with other Azure services or mobile and desktop applications such as those made with Xamarin. In this lightning talk, Laurent Bugnion, Cloud Developer Advocate for Microsoft, will give you an introduction to Azure Functions and get you started with this exciting aspect of modern computing.

Singapore: MonkeyFest

A little later in the month, I will fly to Singapore to attend the MonkeyFest conference which is a Xamarin event organized for the first time in the beautiful south east Asian city. There is a nice team of speakers speaking on a variety of topics. The entrance tickets can be purchased for 19 Singapore dollars, which is very cheap for such a quality show! We hope to see a lot of attendees at Microsoft Singapore!

Building truly Universal applications with Windows, Xamarin, MVVM and Azure

With Windows 10 supporting an unprecedented number of platforms and form factors (from IOT to phones to tablets to laptops and desktops to XBOX and SurfaceHub, and even the new HoloGraphic computer HoloLens), the name “Windows 10 Universal application” is fairly accurate. But to be honest, shouldn’t a truly Universal application run on Windows 7, iOS and Android devices too? Thankfully, this is possible thanks to a clever architecture pattern named Model-View-ViewModel, the .NET portable class libraries and the Xamarin frameworks. With these tools, we can structure an application so that most of the code is shared across all the platforms, and then build truly native UI that adapts without any compromises to the device it runs on. In this session, we will understand exactly how such universal applications are built. Laurent Bugnion, a XAML/C# expert, Microsoft and Xamarin MVP who started making universal applications before it was even a thing, will show you practical knowledge with a lot of demos. Come listen from the creator of the popular MVVM Light Toolkit how this powerful but simple library can be leveraged to help you target more users than you ever dreamed of!

Come say hi!

I hope that I will have the occasion to see a lot of you out there. I have more talks coming up in November – but that is for another post. Please come say hi!

Happy coding
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)

Share on Facebook

Running unit tests on Azure Functions in Visual Studio 2017

.NET, Azure, Azure Functions, Microsoft, Technical stuff, Visual Studio
No Comments

TL;DR; You should really update your Nuget packages

I am currently experimenting a lot with Azure due to my new job and also of course due to the really cool innovation that we can find there. Recently I got interested in Azure Functions. This cool feature allows to write a small piece of code that runs on Azure and can be triggered by various events (time based, HTTP-request based, etc). For example, imagine that you have a value that keeps changing and you want to monitor this value and do some kind of analytics on this. In the code I am currently writing, I am using the value of a Bitcoin as the sample, and I am just periodically reading this value and storing it into an Azure database.

For this small functionality, it would be much too complicated to set an entire server-based application up. This is a perfect example for a time-based Azure Function. I am not going to explain more about Azure Functions here, because I am working on a complete article including sample which will do that. But in the course of my investigation, I stumbled upon an issue that can easily be solved.

The problem:

The issue arises when you try to write unit tests for your Azure Function. In many examples I saw, the Azure Function was created straight in the Azure portal, which is great but makes it a bit difficult to unit test the code. Thankfully it is also possible to create the Function project in Visual Studio, and to take advantage of all the features including unit test, code coverage etc.

To do this, try the following:

  • Install Visual Studio 2017. I currently have the Update 3, which is the most recent at this time. Make sure to select the Azure workload when you install Visual Studio!

Click to see the full picture

  • In Visual Studio, select Create new project.
  • In the New project dialog, select Cloud on the left, and then Azure Functions.
  • Give your project a name and then click OK.
  • Right click on the Function project and select Add, New Item.
  • In the Solution Explorer, right click on the solution and select Add, New Project.
  • In the Add New Project dialog, select the Test category, and then Unit Test Project (.NET Framework).
  • Give your unit test project a name and then click OK.
  • In the Unit test project in Solution Explorer, right click the References folder and select Add Reference.
  • In the Reference Manager dialog, select Projects and then the Function project that you created earlier. Then click OK.
  • Build the solution.

If you have the same setup as I have, you will get an error stating something like:

Metadata file ‘C:\Users\Laurent\Documents\Visual Studio 2017\Projects\FunctionApp2\FunctionApp2\bin\Debug\net461\FunctionApp2.dll’ could not be found

Indeed, if you check the path in Windows Explorer, you will see that there are no DLLs under FunctionApp2\bin\Debug\net461. There is however a folder under FunctionApp2\bin\Debug\net461\bin which contains all the DLLs. The issue is that the Functions project does not generate its output to a standard path. As a result, the Unit test project does not find the reference it was expecting.

The resolution

After reaching out to the Azure Functions team, I found out that this is a know issue and that an updated project template for Visual Studio will be released soon. But there is already an easy fix that you can apply to your project today: You just need to update your Nuget packages, and this will apply the fix to the Functions project.

  • In the Solution Explorer, right click on the Solution and select Manage Nuget Packages for Solution.
  • Under Installed, select the Microsoft.NET.Sdk.Functions package.
  • On the right under Versions, select the Function project. Note that the version shown is smaller than 1.0.2 (likely 1.0.0).
  • Below this box, make sure that Latest stable 1.0.2 is selected in the Version combo box and then click Install.
  • Build the project again. This time it should succeed.

Click to see the full picture

Conclusion

This was an easy fix that the Azure Functions team was able to deploy to your project using an update to the Nuget package. Of course, there are good reasons why teams are sometimes reluctant to apply an update: They might fear that the update brings breaking changes, or that something might go wrong unexpectedly due to regression bugs etc. But when you create a brand new project, it is a good idea to apply the Nuget updates to the solution. This way you will make sure that your new project starts with the latest and greatest.

Thanks to the Azure Functions team for their help solving this issue!

Happy coding
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook
 

Solving the #Xamarin error “Unable to copy appname.dll…”

.NET, Technical stuff, Visual Studio, Work, Xamarin
No Comments

If you recently updated Xamarin to the latest stable version in Visual Studio 2015 or Visual Studio 2017, you might have encountered an annoying error when trying to build:

Unable to copy appname.dll from obj to bin because it is being used by another process

This error typically happens the second time that you try to build after you start Visual Studio. The first time everything works OK, then suddenly you cannot build anymore. Cleaning the solution doesn’t help, the only “fix” is to restart Visual Studio which is of course really annoying when you are developing.

This error is known, as shown by the Bugzilla issue #56275. There is also an old forum discussion on the Xamarin forums, which is a bit confusing because it might be a recurring error in the Xamarin updates.

Fortunately, the Bugzilla discussion also carries a workaround. This is a Visual Studio extension that you can install, which should fix the issue. I also talked to Microsoft about this and got confirmation that the error is fixed in a future release of Visual Studio. The engineer who replied to me also gave me a VSIX to fix the issue. I am not entirely sure what the difference is with the one in the Bugzilla issue, so I will just copy it here for your convenience. As far as I can tell, both VSIX files work well.

Happy coding
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook
 

Using the Windows Template Studio with #MVVMLight

.NET, Build, MVVM, Technical stuff, Universal Windows Platform UWP, Visual Studio, Windows 10, Work
1 Comment

Here is a story of a great collaboration between Microsoft and the community.

Last year in August, as I was speaking at VS Live in Redmond, I was asked by my friend Clint Rutkas for coffee because he had an idea he wanted to run by me. Now if you know Clint, that is usually really intriguing and I was really excited to hear about his idea.

Clint told me about the project he was thinking of starting. This was just conceptual at the time, but his idea made a lot of sense: Why not make the process of creating a new Universal Windows application a lot easier. Why not help people with all the tedious tasks that you get right after File, New, Project.

Usually when you get started, you need to add a bunch of pages and helpers to your application. The Blank application template is just that, blank. In MVVM Light, I added a project template for the supported frameworks (Universal Windows Platform, Xamarin.iOS, Xamarin.Android, Windows Presentation Foundation, Silverlight).

2017-05-24_11-09-27
The MVVM Light templates in Visual Studio 2017

However creating a meaningful project template is really difficult. You are constantly navigating between “too much content” and “too little content”. If you have too much, the developer ends up having to remove a whole lot of code, which is tedious. If you have too little, then the developer needs to spend time adding the basics, as well as sometimes having to look for guidance on how to do common things like navigation, dialogs, a Settings page, etc.

Building a wizard

Of course I thought of building a wizard to help people getting started. This is not easy though. First of all, the Visual Studio automation can be complex. You need to support multiple versions of Studio, and the extensibility model changes from version to version, so that is a big commitment. And this is where Microsoft has a huge advantage, they own the extensibility model, they know in advance is something is going to change, and they have the resource to create and maintain the code. And since the WTS is open source and available on Github, you can also contribute, and help make this project even better.

Installing the Windows Template Studio

Before you get started, you will need to add the Windows Template Studio (WTS) to Visual Studio 2017. Thankfully this is really very easy. In Visual Studio 2017, just select Tools, Extensions and Updates. Click the Online item on the left, and enter Windows Template Studio in the search box on the top right.

2017-05-24_09-47-08
The Extensions and Updates dialog with WTS

In Visual Studio 2017, you are now required to close the application to install the extension, so after the download is complete, close Studio and it will get installed.

Getting started

2017-05-24_11-16-46

The WTS starts in the File, New, Project dialog. Under the usual Universal Windows templates, you will see the entry for the WTS. Select it, give a name to your new application and press OK.

The project type

2017-05-24_11-19-16
The project type and framework dialog

The next screen is about the foundation of your app. You can select a type of navigation (currently you can select an app with a navigation pane, or an app with tabs), or simply a blank template without navigation.

The framework

Then comes the framework selection. This is where you will notice MVVM Light front and center. The other options at the moment are Code Behind, or a basic “no-name” MVVM implementation which can be useful in situations where the usage of 3rd party frameworks is completely forbidden.

The pages

2017-05-24_11-20-12
The pages dialog

The next step is probably the one I am the most excited about. It is usually so tedious to add the same pages over and over in every application I create. Here, you can choose to add pages such as blank page, map page, master/details, web view, settings etc. I can’t stress enough how much of a time saver this step is.

Note that the studio also supports you in finding out which licenses the 3rd party frameworks use. For example, if you add a Settings page which uses JSON.Net for the serialization of the settings, a link to the license is added to the Summary pane on the right, and so you don’t have any surprise.

The features

The features dialog is as exciting. With one click, you can add new experiences to your application such as Suspend/Resume, Background tasks, notifications, live tiles and more.

2017-05-24_11-54-40
The features dialog

This is probably the easiest way to offer a fully featured application to your users.

Why only MVVM Light at this time?

Microsoft ran numbers of the Nuget downloads and saw a confirmation that MVVM Light is the most widely used framework to build MVVM applications on Windows. In addition, its modularity and simplicity of use makes it a prime candidate for the first version of the WTS. However this is an open source project and so the developers of other projects (such as my good friends at the Prism or MVVM Cross projects) are already working to add support for their own framework in the WTS.

What about other application types?

At the moment, the WTS only works for Universal Windows applications. However nothing would prevent it to be updated for other application types. Personally I would welcome Xamarin support! And here we can predict that this will probably happen sooner or later, supported by the community of open source developers. I can see a lot of advantages in adding support for Xamarin or even WPF desktop applications. So I encourage everyone to head to Github and start contributing!

Resources

Here are some videos and links to get started:

I hope that you also see the potential of this great tool and that you will contribute.

Happy coding!
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook
 

Live blogging the Microsoft Build keynote, day 2 #msbuild

.NET, Build, Conferences, Technical stuff, Universal Windows Platform UWP, Visual Studio, Windows 10, Work, Xamarin, XAML
No Comments

And the show continues on day 2! In this post, I will be live blogging the Microsoft Build keynote on day 2. This should be a very exciting event with focus on client development, Windows and Mixed Reality. Get ready!!

Live blogging the Microsoft Build keynote, day 1 #msbuild

.NET, Build, Conferences, HoloLens, Technical stuff, Universal Windows Platform UWP, Visual Studio, Windows 10, Work, Xamarin, XAML
No Comments

Build day 1 is a wrap and you can find all the live notes taken during the keynote in this post!

My plans for Build 2017 #msbuild

.NET, Blog, Build, Conferences, Technical stuff, Universal Windows Platform UWP, Visual Studio, Windows 10, Xamarin
No Comments

Days are passing and the time is getting closer to pack my stuff and fly to Seattle again. This will be my first trip to my third home this year, and I am really impatient to be there. I just love that place.

Getting there

I will be arriving in town on Saturday evening, quite late. My plan is to pick a rental car and get to the hotel in Pioneer Square and get to bed :) The next morning, based on experience, I will be up super early (thank you jet lag). This is a droning day! I am not 100% sure yet where I will drive but I am considering getting close to Rainier National Park if the weather is good enough. Alternatively maybe take the ferry to Bainbridge to make footage of the islands. Or maybe the Snoqualmie area. Or maybe all of the above. This will be a day like I love, driving around on my own schedule, relaxing, flying, filming, editing pictures at a cafe… Should be a lot of fun if the clouds are cooperating!

Visiting the office

Monday will be an office day. Seattle is an important hub for Valorem, and this is the office where it all started for me. I love going there and seeing the new and improved space. So as usual I will be looking forward to meet new colleagues and meet old colleagues again!

The conference: Live blogging

During the conference itself, I will try something new this year: I will be live blogging the keynotes and the sessions that I can attend. In previous years, I was always taking notes during the events and posting these notes to my blog every so often. Surprisingly, this has been quite popular, even though these are my raw notes without much commentary. I found out that not everyone can watch the live stream, and people were reading my notes and getting some of this keynote feeling there. But of course posting a blog post is a lot slower than taking the actual note. So this year I installed a new plugin on my blog called 24LiveBlog. This will allow me to publish my notes about the keynote in real time as well as hopefully post pictures too. That should be a fun exercise!

You will be able to follow the live blogs at the following URLs. However please note that these links will only be active on and after the keynote day 1 and 2 respectively!

Keynote day 1 (Wednesday May 10, 2017): http://blog.galasoft.ch/posts/?p=1601
This keynote will take place from 8AM to 11AM PST
(4PM London time, 5PM Zurich time).

Keynote day 2 (Thursday May 11, 2017): http://blog.galasoft.ch/posts/?p=1606
This keynote will take place from 8:30AM to 10AM PST
(4:30PM London time, 5:30PM Zurich time).

I am really looking forward to this exercise and hope that it will be useful to you all!

Wednesday: Mix2017 party with iHeartRadio and Valorem

Yes yes I know, the name is really significant… this is not a revival of the MIX conference! I know we all miss this amazing conference… No, the Mix2017 event is Valorem’s and iHeartRadio’s party at Build!

Join iHeartRadio and Valorem for #Mix2017, a fantastic night where music meets mixed reality. iHeartRadio’s DJ will mix your favorite music and Valorem will mix your reality with exciting HoloLens experiences on Wednesday, May 10, at the Living Computers Museum + Labs. As a bonus, event attendees get free admittance to the museum.

More details and registration on the Valorem website! I hope to see many of you at this event!

Happy coding!
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook
 

Setting the device brightness on Windows with WPF

.NET, Technical stuff, Windows 10, Windows 7, Windows 8, Work, WPF
3 Comments

I am working on a project which I can’t really detail, but one aspect caused me a few headaches. Finally I reached out to the Windows team at Microsoft and got great help from Katie Anderson who works on the brightness team. This was quite tricky, and we had to have a couple of roundtrips before we managed to find a way that worked.

Well, why?

In the application I am working on, it is necessary for the user to set the device brightness from the application itself. You might wonder why, because most Windows devices have hard keys to set the monitor brightness. For example on a Surface, you can use the Fn-Del and Fn-Backspace key combinations to alter the brightness of the screen. Or you can of course swipe from the right side and use the Brightness button to change the value in the Action Center.

However on that particular project, the user doesn’t have access to the keyboard, nor to the Action Center. This is a kind of kiosk scenario if you will where many of the Windows features are deactivated by policies, and no hard keyboard is provided. I had to find a way to do this programmatically.

First approach: Not so good

At first I thought I would have my application’s main window run in full screen and set a black Rectangle on top of everything, and change the Rectangle’s opacity in my code. That worked well but of course it wouldn’t work if other applications were in the foreground (yes, I forgot to mention, it’s a kiosk app which can start other apps and put them in the foreground…).

Second approach: Better but not great

OK, no problems I thought, let’s have my app open a modal full screen window which is always on top. I will then have this window made insensitive to touch or mouse clicks with the following code. Finally, this window will have the black Rectangle and be on top of everything all the time.

public static class WindowsServices
{
    private const int GwlExstyle = -20;
    private const int WsExTransparent = 0x00000020;

    public static void SetWindowExTransparent(IntPtr hwnd)
    {
        var extendedStyle = GetWindowLong(hwnd, GwlExstyle);
        SetWindowLong(hwnd, GwlExstyle, extendedStyle | WsExTransparent);
    }

    [DllImport("user32.dll")]
    static extern int GetWindowLong(IntPtr hwnd, int index);

    [DllImport("user32.dll")]
    static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
}

This worked OK but somehow it was not satisfying. I really wanted to have a solution where my app would modify the actual device brightness. There are a few reasons why the client also wanted that, and so I started to investigate deeper. Unfortunately, Bing searches (and the equivalent Google searches) didn’t really return anything satisfactory.

Using Powershell

After searching a bit, I got a first clue that what I wanted to achieve was doable: You can query and modify the device brightness from Powershell with the following script:

CODE TO GET THE BRIGHTNESS INSTANCE

PS C:> Get-Ciminstance -Namespace root/WMI -ClassName WmiMonitorBrightness

CODE TO SET THE BRIGHTNESS

PS C:\Users\lbugn> $monitor = Get-WmiObject -ns root/wmi -class wmiMonitorBrightNessMethods
PS C:\Users\lbugn> $monitor.WmiSetBrightness(50,10)

If you run these commands in Powershell, you will marvel at the result: Yes it does work and the screen’s brightness is modified. Great Scott, I am on the right track! The key to this is the WMI (Windows Management Interface) class WmiMonitorBrightness.

Converting to .NET

The next step was obvious: I needed to convert the Powershell script to some usable .NET code. Unfortunately, easier said than done. This is where I reached out to Microsoft for help and thankfully Katie really followed through and after a few iterations we got it to work.

First she used the WMI Code Creator tool to convert the Powershell script to .NET. I had no idea that such a tool existed, but then again I never had to dive so deep in the entrails of Windows. Unfortunately when running the code that the tool created (which I won’t post here to avoid confusion), I got some errors. One more roundtrip to Redmond (via email) and Katie found the way: The following code will indeed modify the brightness of the screen, yay!!

public static class WindowsServices
{
    private static ManagementObject _brightnessInstance;
    private static ManagementBaseObject _brightnessClass;

    static WindowsServices()
    {
        // Querying the Windows service to get the Brightness API.
        var searcher = new ManagementObjectSearcher(
            "root\\WMI", 
            "SELECT * FROM WmiMonitorBrightness");

        var results = searcher.Get();
        var resultEnum = results.GetEnumerator();
        resultEnum.MoveNext();
        _brightnessClass = resultEnum.Current;

        // We need to create an instance to use the Set method!
        var instanceName = (string)_brightnessClass["InstanceName"];
        _brightnessInstance = new ManagementObject(
            "root\\WMI",
            "WmiMonitorBrightnessMethods.InstanceName='" + instanceName + "'",
            null);
    }

    public static int GetDeviceCurrentBrightness()
    {
        // Getting the current value.
        var value = _brightnessClass.GetPropertyValue("CurrentBrightness");
        var valueString = value.ToString();
        return int.Parse(valueString); // Direct cast fails.
    }

    public static void SetDeviceBrightness(int newValue)
    {
        if (newValue < 0)
        {
            newValue = 0;
        }

        if (newValue > 100)
        {
            newValue = 100;
        }

        var inParams = _brightnessInstance.GetMethodParameters("WmiSetBrightness");
        inParams["Brightness"] = newValue;
        inParams["Timeout"] = 0;
        _brightnessInstance.InvokeMethod("WmiSetBrightness", inParams, null);
    }
}

I made a small sample here which gets the current value of the screen brightness and then increases it by 10% every time you click on a button. When you reach 100%, it goes back to zero on the next click. Simple enough, and does the trick.

I hope that this will be useful to a reader looking for the same feature. I’d love to be the first one to ever blog about this. I doubt that I am, and probably someone will point me to the article that I never found :) but seriously, I really couldn’t find any mention of something like that on the whole WWW.

Happy coding!
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)

Share on Facebook