A decent part of my work is in customizing Service Manager.

Last year i was contributing author on the Service Manager 2012 Unleashed book, specifically writing chapters about customization (together with Kurt Van Hoecke)

The chapter 23 talks about creating your own forms in Service Manager.

Get the book here: http://www.amazon.com/System-Center-Service-Manager-Unleashed/dp/067233707X/ref=sr_1_1?ie=UTF8&qid=1422965008&sr=8-1&keywords=service+manager

 

In this article I want to show how you in a very easy way can disable controls, based on if it is a new object (creation) or existing object (editing).

I have specifically used this method to lock the field that is the key.

In this case I have a “Name” textbox which is the key of the item, to make sure that a user does not change the name later on.

 

When I make my form, I set the text binding on the textbox to the name property of the data item.

  <TextBox Text="{Binding Name,Mode=TwoWay}" MaxLength="256"  Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1"  Margin="2,2,2,2"/>

now comes the good stuff:

To be able to enable/disable this textbox, all i have to do is to bind the “IsEnabled” property of the control to the “$New$” property in the dataitem/datacontext.

But since the name of the property contains special characters ($), it is not possible to just write the name.

What you need to do is to add [ ] around the property name in the binding.

Making the complete XAML control look like this:

<TextBox IsEnabled="{Binding [$IsNew$],Mode=TwoWay}"  Text="{Binding Name,Mode=TwoWay}" MaxLength="256"  Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1"  Margin="2,2,2,2"/>

 

notice the [$IsNew$] which binds the enabled property of the textbox to the $IsNew$ property in the dataitem

 

Any comments is welcome!

Have fun!

And see you next week on NIC! www.nicconf.com