Syndicate

News

My name's Marco De Sanctis and I'm an IT professional from Italy. This is my technical blog, about .NET and related application development and design technologies.

Download my Resume (.doc)

Recent Comments

7/28/2008 at 2:46 PM

Hi...What kind of problem are you experiencing?...
by Marco De Sanctis

Read more...

7/28/2008 at 12:59 PM

Very nice concept and can i expect for list box? ,...
by Sudhir Malireddy

Read more...

7/28/2008 at 9:58 AM

In aggregates the rula is: who is the rool element...
by Tommaso Caldarola

Read more...

7/22/2008 at 7:49 PM

Been there too in a past project! I remember this ...
by Mathias

Read more...

7/14/2008 at 11:50 PM

Sure I am... but if you got batches that last for ...
by Marco De Sanctis

Read more...

Recent Posts

Crunch mode is a pure waste of time, energy and money

7/31/2008 at 5:41 PM

Read more...

Double Click on the .sln file doesn't open Visual Studio on Vista

7/27/2008 at 9:02 AM

Read more...

Domain Model & Aggregates: when do master-detail associations happen?

7/22/2008 at 4:08 PM

Read more...

How I Got Started in Software Development

7/14/2008 at 12:16 AM

Read more...

Unleash the power of VisualStateManager with custom states

6/30/2008 at 12:12 AM

Read more...

June 2008 Entries

Property triggers are the WPF feature I miss the most in Silverlight 2: I really liked writing behaviors in declarative style with XAML and Styles and it was somehow frustrating being forced to use C# code and event handling to achieve similar results in Silverlight.

Although it's not here for exactly the same puropose, VisualStateManager is a great improvement to fill the gap thanks to:

  • Blend visual support
  • automatic state transition animation

Those two features, combined with the opportunity to inject custom states at your own will, make VisualStateManager so poweful that you're going to miss it once back to WPF, at least until it won't be supported for smart clients too.

Let's suppose I want to animate a textbox to change its background color when mouse pointer overs it. If I was in WPF I would have attached a trigger to the IsMouseOver property, in Silverlight we got no triggers, but we have Blend and VisualStateManager.

So what I do is putting a TextBox in my UserControl and ask Blend to customize its template:

image

As we can see, we got no states for the standard TextBox so VisualStateManager seems to be unuseful at first: should we once againf rely on procedural code to achieve our goal? Not at all (or, more exactly, almost not at all). Even though standard TextBox has no built-in states (it doesn't specify any in its attributes nor it invokes any state transition, as, for example, Button does) we can easily add our own simply editing the generated style XAML markup.

What we need is a custom StateGroup, called MouseStates, and a couple of states, Normal and MouseOver, so what we do is opening Visual Studio to have intellisense while typing, adding a reference to System.Windows namespace and writing the following lines of code:

image

Visual Studio complains about using VisualStateManager.VisualStateGroups attached property; however, don't care about it, everything will compile without errors. Ok, now back in blend to continue editing the control template:

image

As you can notice, Blend recognizes the 2 newly added states and suddenly adds them to the States panel. Now, we can animate the TextBox background as we would usually do:

image

Now we only need one last step: adding some code to invoke state transitions when the mouse pointer overs or moves away from the TextBox. So, back in Visual Studio, let's add a couple of event handlers:

image

Now, if you build and run the project, you'll notice how the TextBox gracefully changes its background color from white to shaded red. However, our textbox won't work in another UserControl unless we don't add the same event handling code to it. It would be preferrable to build a custom StateTextBox and internally hiding all that logic. Doing it is extremely easy, as it consists only on creating a class which inherits form Textbox and writing code similar to the previous one:

image

Notice the two attributes I added to the class declaration to describe the control's state machine structure; Blend is supposed to read them to show controls states when editing its template. Unfortunately, (as I wrote some days ago) Blend June CTP current version has template editing capabilities only for controls which belong to System.Windows.dll. It means that even if we use StateTextBox, we'll still need to manually do all the stuff. However, it still has the advantage to leave the page code behind free from any textbox state transition code.

As usual, source code is available here.

kick it on DotNetKicks.com

I've been recently doing some experiments on Silverlight and the new Blend June CTP. I'm amazed by the design support to custom template editing it provides, although I couldn't get it work with my own custom controls.

I though I was mistaking something, perhaps forgetting some attribute or whatever else; after 2-3 days of tests, I finally gave up...

Today I've found this post explaning that

Currently Blend doesn't support copy ControlTemplate that are not define in System.Windows.dll. But you should be able to create an empty template and edit it.

Ok... at least it wasn't a fault of mine..

Technorati Tags: ,

TransactionScope constructor has an overload that lets you specify a transaction timeout:

image

The example above sets up a 1 hour timeout on the new transaction. I was using a similar approach to execute an Oracle stored procedure which was doing some batch processing that took about 30 mins. to complete. Anyway, I could se the transaction being rolled back after about 10 minutes, even though the OracleCommand itself had a proper timeout and no exception was raised by the underlying stored procedure.

Pretty strange, isn't it?

After some research, I've discovered that the TransactionManager class, which ultimately manages the transactions lifespan, has a readonly MaximumTimeout property, that can be set only at machine.config level and has a default value of 10 minute:

image

This is the maximum time limit your transaction can last, regardless of what you specify on the aforementioned constructor. In my case, I decided to move it to one hour limit.

Hopes this saves you a little time ;-)

kick it on DotNetKicks.com

As Corrado Cavalli pointed out in his blog (sorry, it's in Italian), in Beta 1 custom controls didn't inherit their parent's default template; that means they didn't have any visual representation unless we explicitely provide a default template for them. It was a bit annoying, especially when we only needed to add some logic to standard controls, like creating a CustomTextBox that accepts only numbers, for example.

I was happy to realize that in Beta2 this limitation has gone: when building custom controls, we no longer have to create a default template for it, as it's inherited from its base class (if none is provided). Starting from Corrado's example, let's create a CustomButton class

image

Now, if we place it in a Silverlight user control:

image

we obtain exactly what we expected:

image

Fair enough!

If you are excited about Silverlight 2 as I am, and you can't wait for its upcoming beta realease, you'll surely enjoy this: Silverlight 2 Beta 2 SDK Documentation is available.

Let's hope it anticipates the SDK public download only for a few hours.

kick it on DotNetKicks.com

Technorati Tags: