Dutton's blog

Developer! Developer! Developer! (DDD) East Anglia 2013 Review

I've just got back from DDD East Anglia. This was my first software conference. Although I've been in the industry for over 10 years now I've never managed to get to one, but DDD's policy of holding them at weekend is brilliant (even if it is the same weekend as the British GP ;)).l

An innocent query (from my Red Bull work email) to the organisers about the wifi situation at the venue led to an invite to give a lunchtime "grok" talk on Software Development at Red Bull Technology, so it was a bit of a baptism of fire today (that room looks a hell of a lot bigger from the front, a lot of faces looking back).

Anyway I really enjoyed it, if you've not been to a DDD event I thoroughly recommend it, a lot of very interesting talks from some very knowledgable people (and in today's case some flustered chap babbling about F1). This will definitely not be my last.

Code Snippet: A recursive WPF Visual Tree child search

For when you want to find a child of a given type anywhere below a root element in the visual tree. I always end up writing these, so though I might as well post it for reference / review. Another candidate for a shared library.

private static DependencyObject RecursiveVisualChildFinder<T>(DependencyObject rootObject)
{
    var child = VisualTreeHelper.GetChild(rootObject, 0);
    if (child == null) return null;


      
Windows Phone 8 Development Notes

As a WPF developer, I'm finding the jump to Windows Phone 8 development not as seamless as I had first hoped, here are some of the small differences that have bitten me so far (certainly more to come, I'll be adding to this list and have a few blog posts on the way with some more detail)

TextBlock

MultiBindingConverter

  • Windows Phone doesn't support IMultiBindingConverter, I'll be blogging about a workaround soon.

Style Triggers

  • There are no style triggers in Windows Phone OS, I wanted to change the appearance of a ListBoxItem based on its IsSelected property and had to resort to using VisualStates instead, more to follow.
appSettings, applicationSettings and custom configSections in app.config

For some reason the different ways of handling application settings in C# always throws me, probably because I tend to write it once and forget about it until it comes up again many months later.

<applicationSettings>

If you create a default settings file in my Project, which creates an app.config and a Settings.settings under Properties, entries here can either be in User or Application scope and result in entries added to the app.config file under <applicationSettings> or <userSettings> sections appropriately, looking like this:

 
<userSettings>
<AppConfigTest.Properties.Settings>
<setting name="MyUserScopeSetting" serializeAs="String">
<value>foo1</value>
</setting>
</AppConfigTest.Properties.Settings>
</userSettings>
<applicationSettings>
<AppConfigTest.Properties.Settings>
<setting name="MyApplicationScopeSetting" serializeAs="String">
<value>foo2</value>
</setting>
</AppConfigTest.Properties.Settings>
</applicationSettings>

These can then be accessed from within your code using:

 
var setting1 = Properties.Settings.Default.MyApplicationScopeSetting;
var setting2 = Properties.Settings.Default.MyUserScopeSetting;

These will appear under your Intellisense in Visual Studio.

You can also write to these, just make sure you call Save() afterwards:

 
Properties.Settings.Default.MyApplicationScopeSetting = "new value";
Properties.Settings.Default.Save();

<appSettings>

You might also find app.config files containing elements added directly to an appSettings section like this:

 
<appSettings>
<add key="MySetting1" value="Value 1" />
<add key="MySetting2" value="Value 2" />
</appSettings>

These can be accessed using the ConfigurationManager:

 
var setting1 = ConfigurationManager.AppSettings["MySetting1"];
var setting2 = ConfigurationManager.AppSettings["MySetting2"];

This is accessed by key string, so will not appear under Intellisense, but will return null if the key doesn't exist.

Note that there is no type checking with appSettings; you cannot safely assume the type of the configuration item and someone could have changed your integer to a string in the config file for all you know and you'd have to deal with it.

Custom configSection

A third, and I believe now recommended since .Net 2.0 approach is to create a custom configSection within app.config. This needs to be represented in code, through a class which derives from ConfigurationSection:

    public class MyExampleConfigurationSection : ConfigurationSection
    {
        private static readonly ConfigurationProperty MyExampleString;

        private static readonly ConfigurationPropertyCollection ConfigurationProperties;

        static MyExampleConfigurationSection()
        {
            // Define your configuration properties here
            MyExampleString = new ConfigurationProperty("myExampleStringValue", typeof (string), null,
                                                         ConfigurationPropertyOptions.IsRequired);

            ConfigurationProperties = new ConfigurationPropertyCollection {MyExampleString};
        }

        [ConfigurationProperty("myExampleStringValue", IsRequired = true)]
        public string MyExampleStringValue
        {
            get { return (string)base[MyExampleString]; }
        }

        protected override ConfigurationPropertyCollection Properties
        {
            get { return ConfigurationProperties; }
        }
    }

Like the userSettings and applicationSettings sections, built-in configuration sections must be explicitly defined in a new sectionGroup under configSections, like so:

 
<configSections>
<section name="example" type="AppConfigTest.MyExampleConfigurationSection, AppConfigTest"/>

</configSections>

can be set like this:

 
<example myExampleStringValue="Foo"/>

and then queried in code like this:

             var myExampleConfigurationSection =
                ConfigurationManager.GetSection("example") as MyExampleConfigurationSection;
            if (myExampleConfigurationSection != null)
            {
                Console.WriteLine(myExampleConfigurationSection.MyExampleStringValue);
            }
Microsoft 70-484 Essentials of Developing Windows Store Apps using C# Exam Passed

Further to my studies towards the MCSD: Windows Store Apps Solution Developer certification, today I took and passed the Microsoft 70-484: Essentials of Developing Windows Store Apps using C# exam.

I found this exam quite difficult, and to be honest only just scraped a pass this time. Although my work is predominantly WPF with more recent WinRT and Windows Phone 8, my Windows Store experience has been limited to home projects so that's probably why this was a challenge.

I used the excellent Jump Start video tutorials on the Microsoft Virtual Academy along with some further reading around the course content, but in hindsight I wish I had focused more on the specifics of Store App development, in particular the Windows 8 Built-In Controls and App Store layouts rather than just plain WPF.

Either way, a pass is a pass... Just one more to go before MCSD.