Blend doesn’t support managed type converters

If you are busy trying to develop using Microsoft Silverlight 2 beta 2 and Microsoft Expression Blend 2.5 June Preview you might have encountered errors while working in Blend such as The TypeConverter for "DataGridLength" does not support converting from a string. although Visual Studio doesn’t complain about the XAML and the code runs just fine.

Well its a confirmed issue in Expression Blend according to the feedback I’ve received on my bug report. The official word from Microsoft is as follows:

Thank you for your feedback. For the June Preview Blend does not support type converters from managed code (all the type converters defined in non-runtime assemblies). This is something that we are working on supporting for RTM but unfortunately do not have it working yet.

What this means is that any custom control development, including Microsoft’s own controls can potentially suffer from this issue as TypeConverter implementations that are not part of the Silverlight 2 beta 2 runtime are not supported. If you have encountered this issue in Expression Blend then please rate and validate the bug so it will be fixed.

WatermarkedTextBox control for Silverlight 2 beta 2

Microsoft SilverlightWhen Microsoft released Silverlight 2 beta 1 they included a really cool control called the System.Windows.Controls.WatermarkedTextBox control. It lived in the assembly System.Windows.Controls.Extended.dll and was included in your XAP file when you did a build. However in Silverlight 2 beta 2 the one control that didn’t make it was the WatermarkedTextBox control.

So by popular request, I have upgraded the original source code which Microsoft published under the Microsoft Public License, I have repackaged the control to ease the migration of existing beta 1 applications. In order to avoid any confusion I’ve changed the namespace of the control. This should hopefully prevent any issues when or if Microsoft decide to release their own version again.

To use the replacement control, simply build the provided solution and add a reference from your existing project to the assembly CraigN.Windows.Controls.dll and use the namespace CraigN.Windows.Controls. So typically this will involve adding xmlns:CraigN_Windows_Controls="CraigN.Windows.Controls;assembly=CraigN.Windows.Controls" to the UserControl element of your XAML file.

Then simply prefix all WatermarkedTextBox elements in the XAML file with CraigN_Windows_Controls: and all code should build again.

You can download the source code from here. I have taken the time to ensure that original test cases build. If you have any comments or suggestions, I’d like to hear them.

Silverlight 2 Beta 2 now available

Microsoft Silverlight Microsoft earlier this week announced at Tech-Ed North America 2008 that Microsoft Silverlight 2 beta 2 will be available for download this week.

The new Silverlight 2 beta 2 control updates the version number from 2.0.30226.2 to 2.0.30523.6. This release is expected to break compatibility with Silverlight 2 beta 1 while improving compatibility with Silverlight 1. For a full list of changes and new features, take a look here.

Please note, that you should uninstall all previous Silverlight 2 beta 1 bits before you attempt to install the new beta bits. The Silverlight 2 beta 2 control seems to upgrade seamlessly enough though. A list of stuff that should be removed includes:

  • Microsoft Expression Blend 2.5 March Preview
  • Microsoft Silverlight Tools Beta 1 for Visual Studio 2008
  • Microsoft Silverlight 2.0 SDK Beta1

Also note that the Microsoft Silverlight Tools Beta 2 for Visual Studio 2008 will install fine on top of Visual Studio 2008 RTM or Visual Studio 2008 Service Pack 1 Beta.

Well they were really cutting the before the end of the week promise close but you can now get hold of the latest beta developer bits using the following links:

If you aren’t using Visual Studio 2008 then you can download the SDK on its own using the following link:

I’ve also noticed another build of the Silverlight 2 beta 2 control that is targeted for developers. I assume it has more debugging support as its slightly larger in size. I don’t think its included in the Microsoft Silverlight Tools Beta 2 for Visual Studio 2008 installer.

And if you liked the Deep Zoom technology that was first shown in Silverlight 2 beta 1 then get yourself an updated set of tools to work with Silverlight 2 beta 2:

I personally can’t wait to get started with this new build as it now finally carries a commercial Go Live license.

Take a look at the following post which goes into details about the new features in the Silverlight Tools for Visual Studio 2008.

  1. WCF templates for Silverlight Enabled.
  2. Build configurations.
  3. XAML Validation now reports build errors.
  4. Setup Improvements.
  5. Projects created in Beta 1 are prompted for conversion when opening to Beta 2
  6. Linking a Web Site to a Silverlight Application.

[tags]Silverlight,Silverlight 2,Tech-Ed[/tags]

How to switch Silverlight UserControls

One of the guys on the official Silverlight community forums posted an interesting question, namely how does one change the currently visible UserControl in a Silverlight 2.0 application. To put things in context the new Silverlight 2.0 project template creates two classes for you: a System.Windows.Application derived class named App with the associated App.xaml and App.xaml.cs files; as well as a System.Windows.Controls.UserControl derived class called Page with the associated Page.xaml and Page.xaml.cs files.

The App class takes care of the initialization and basically you assign a new instance of your Page class to the App.RootVisual property and through the power of Silverlight it appears on your screen. 🙂

So if you wanted to change the currently displayed UserControl for another instance naturally you’d try and set the App.RootVisual property to another instance of a UserControl. This sounds great in theory but it seems that its a single assignment property. Pete Brown’s blog post happens to make mention of this.

So in a quest to solve the problem I’ve implemented a very simple UserControlContainer class that allows the developer to switch controls at runtime without having to deal with the set once RootVisual property.

Simply create a new UserControl called UserControlContainer and copy the following into the UserControlContainer.xaml.cs file:

    public void SwitchControl(UserControl newControl)
    {
        LayoutRoot.Children.Clear();
        if (newControl != null)
        {
            Height = newControl.Height;
            Width = newControl.Width;
            LayoutRoot.Children.Add(newControl);
        }
    }

Next set your Application instance RootVisual to an instance of the new UserControlContainer in the Application_Startup method.

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        // Load the main control
        this.RootVisual = new UserControlContainer();
        Page page = new Page();
        ((UserControlContainer)this.RootVisual).SwitchControl(page);
    }

Then wherever you need to switch out the active control, simply call the following if you are inside App.xaml.cs:

    TestControl1 testControl = new TestControl1();
    ((UserControlContainer)this.RootVisual).SwitchControl(testControl);

Or the following if you need to switch controls from elsewhere:

    TestControl1 testControl = new TestControl1();
    ((UserControlContainer)Application.Current.RootVisual).SwitchControl(testControl);

If you find this useful or find any issues with this method, let me know so I can improve it for all.

 

Updated 2008-03-13: Added Application_Startup example. Thanks to Maurice for pointing this omission out.

[tags]Silverlight 2.0,code,example[/tags]

The pain of SQL Server and working with dates

How many times have you tried to design an efficient database table design in SQL Server only to stumped with the problem of storing pure date values. Yes the currently released versions of SQL Server (up to 2005) don’t support a pure date only data type. Note that SQL Server 2008 add the new DATE data type which should make this post semi-redundant. This can prove painful when you wanting to store values for a specific day. So you end up getting creative. My normal solution is to put a check constraint on the column to enforce that the date value represents the start of the day or 00h00. Oh and I generally make sure I store all my date and time values in UTC so I can render to any time-zone that my application desires.

Here is an example of how I’d do a check constraint on column UtcDate. Note how I effectively truncate the floating-point representation of the date and time value and check that it equals the column value. Also I store it as a SMALLDATETIME as I’m not needing more than 1 minute accuracy. Oh and I’ve tried to reformat the examples to be easier to read on the web, I hope it works. 🙂 

CREATE TABLE [dbo].[Foo]
(
 [UtcDate] SMALLDATETIME NOT NULL
            CONSTRAINT [CK_Foo_UtcDate]
             CHECK (FLOOR(CONVERT(FLOAT,[UtcDate]))=CONVERT(FLOAT,[UtcDate]))
) ON [PRIMARY]
GO

This method works great for me but in searching for a way to truncate the minutes of a DATETIME to a specific interval I found another approach that not only looks more elegant but most likely performs a lot better. I haven’t run any proper performance tests so I’d appreciate some feedback from those that have done some testing.

CREATE TABLE [dbo].[Foo]
(
 [UtcDate] SMALLDATETIME NOT NULL
            CONSTRAINT [CK_Foo_UtcDate]
             CHECK (DATEADD(DAY,DATEDIFF(DAY,0,[UtcDate]),0)=[UtcDate])
) ON [PRIMARY]
GO

It looks a lot more efficient than my previous approach, hopefully it is. Oh and take a look here for more very useful tips and tricks when working with dates and times in SQL Server.

[tags]SQL,SQL Server[/tags]

SQL Server 2008 Compression

Jonathan Allen and Chad Boyd have interest blog posts on the new SQL Server 2008 compression features.

Row level compression drastically reduces the meta-data needed for variable length columns. Instead of storing the length of each field in 2 bytes, it now takes a mere 3 bits. Fields themselves are also smaller. Storing a 1 in an int field now only takes a single byte, though of course larger values may use up to 4 bytes.

In my opinion the new feature shouldn’t really be called compression but rather removal of wasted space. Although the concept of sharing common data from multiple rows in the same page is a form of compression and I suppose where the true value lies. It should make for some really interesting indexing strategies and could even motivate some edge use cases for denormalized data.

I really like the built-in backup compression and the idea that pages will only be compressed when its nearly full. I think the decreased physical data storage I/O will have a significant performance benefit over the CPU performance penalty introduced by the compression and decompression of data.

[tags]SQL Server 2008[/tags]

Juval Lowy to present WCF for the South African community

Juval Lowy Thanks to Dariel Solutions who are bringing Juval Lowy out to South Africa to present a 5-day master class. Juval is recognised by Microsoft as a Software Legend and one of the world’s top .NET experts. For those that are not so lucky to be able to make it to the 5-day course will be pleased to hear that Juval will be giving a free presentation to the SA Developer .NET community on the evening of the 29th of November as well. His talk is titled “Demonstrating Windows Communication Foundation – Beyond the Endpoints, An evening with Juval Lowy”. Make sure you book your seat early as I’m sure this event is likely to be very popular.

[tags]Juval Lowy,WCF,South Africa,SA Developer .NET,Dariel Solutions,event[/tags]

Net60 Beta 1 released

Red Five Labs logo Local mobile innovation company, Red Five Labs, has today released a beta 1 build of their of implementation of the .NET Compact Framework 1.0 which runs on Symbian S60 3rd edition devices like the Nokia N95 series of mobile phones. This is an important product for enterprise developers that would like to deploy on both Windows Mobile and Symbian mobile devices. The official press release follows.

Johannesburg, South Africa, November 14th, 2007 – Red Five Labs, a leading mobile technology company, releases Net60 (beta 1) for immediate download. Net60 is a ground breaking implementation of the .NET Compact Framework running on S60 3rd edition devices.

Net60 enables managed Windows Mobile applications to run unchanged on S60 devices. Using C# and Visual Basic .NET in Visual Studio, developers can now use the .NET Compact Framework environment to build applications for Symbian devices.

Symbian developers can now also write applications for S60 and benefit from the RAD capabilities which .NET development offers.

This beta release is intended for System Integrators and Independent Software Vendors (ISVs) who are interested in exploring the possibilities of Net60 ahead of the commercial release later this year. User feedback is highly encouraged.

For download instructions and an application to join the beta program, please visit the download beta page at http://www.redfivelabs.com/content/download.aspx

Applications will be approved as efficiently as possible by the team at Red Five Labs so that beta testers are able to gain rapid access to the download. Managed support is provided by an integrated support ticket system and public forums.

Any questions  regarding the sign-up of the beta can be directed to support@redfivelabs.com

[tags].NET Compact Framework,Red Five Labs,Symbian[/tags]

Windows Live Tools CTP

Windows Live Tools logo Angus Logan, Senior Technical Product Manager for Windows Live, just announced on his blog the first CTP for a cool set of add-ins for Visual Studio 2008 (formerly code-named Orcas) for getting started with Windows Live in your own applications.
Windows Live™ Tools for Microsoft® Visual Studio® are a set of control add-ins to make incorporating Windows Live services into your Web application easier with Visual Studio 2008 and Visual Web Developer 2008.

Download the Community Technical Preview of  Windows Live Tools for Microsoft Visual Studio Now

The four controls included in this CTP release are:

  • Contacts Control
  • IDLogin Control
  • IDLoginView Control
  • SilverlightStreamingMedia Control

Update: Check this page out for more information.

[tags]Windows Live,Visual Studio 2008[/tags]

Expiring VS2008 beta 2 VPCs

Sometimes Microsoft knows how to screw things up. Not only were the Visual Studio 2008 (code-named Orcas) Beta 2 Virtual PC (VPC) images rather excessively large for the average South African developer to download and too big to fit onto a single DVD for community distribution, but now they are expiring on the 1st of November 2007 as well.

Now I was kind of expecting an new release candidate build to emerge for download sometime soon but it seems that the Visual Studio team has no such intention and has instead released updated beta 2 VPC images. Its not clear at this stage as to whether you need to just download the base image or whether you need to download the entire set of VPC images again. Either way the Visual Studio team lied to us when they said we just needed to get the base images once:

These downloads are differencing disks. To use them, you must also download Visual Studio Code Name Orcas Base Image contains the OS and is a one-time download for all the Virtual PC images that lay on top of it.

Why can’t Microsoft simply release a patch for the base image extending the lifetime of the Windows 2003 operating system? Why do they need to release complete new images? I don’t expect that many South Africa users will continue testing the beta 2 bit any longer if release to manufacturing (RTM) is so close. Sorry Microsoft, you’ve just totally screwed up in my humble opinion.

[tags]Visual Studio,South Africa,rant[/tags]