In my last series I talked about telerik and monitoring a server’s performance.
I used The RadGauge for Silverlight. If you take a close look at the description of the Rad Controls for Silverlight you will notice a block of text which tells this:
Common Codebase and Shared API with WPF Controls All of the controls in the Telerik Silverlight suite are derived from the same codebase with their Telerik WPF counterparts, guaranteeing synchronized future development. Furthermore, both suites share the same API, which cuts in half the learning periods and ensures complete code reusability.
This means (from my point of view – use the same code).
As we (hopefully) know this is not as easy at it sounds – at least in most cases.
There is also a RadGauge for WPF – take care when you open the link – it looks almost the same as the Silverlight counterpart description.
And the samples also look almost the same. It almost looks as the guys building the site are a bit lazy 
I don’t know if they are – as long as the support guys do their job I’m happy.
Anyhow – who knows what “code generators” or something else is going on to make the things look almost the same.
I decided to give this a try – here is what came out.
First I added a WPF application to my existing project.
Next I added a service reference to my per info service.
IMPORTANT: I had to set the checkbox for “create asynchronous…”
So the next idea is to copy the XAML of the Silverlight control to the WPF – of course this can’t work.
The first problem would be the missing reference to the telerik WPF assemblies.
I’m lazy and so I fixed this the easy way. I dragged a Gauge control to my XAML.
And removed it immediately. This adds the references to my project.
Then I switched to my Silverlight Page.xaml and copied the following texblock:
xmlns:control="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Gauge"
xmlns:gauge="clr-namespace:Telerik.Windows.Controls.Gauges;assembly=Telerik.Windows.Controls.Gauge"
xmlns:MySelf="clr-namespace:SLPerfDisp"
Width="460" Height="450"
Yes it worked – except two things MySelf has to point to my WPF app – and height must respect the window border so I changed it to
xmlns:MySelf="clr-namespace:WPFPerfDisp"
Width="460" Height="460"
Next I had to paste the namespaces added by Expression Blend (I change my Silverlight control with Blend this adds some attributes).
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
So it looks as if I’m ready.
In the last moment I noticed – the resources live in
<UserControl.Resources>
while my WPF ones have to live in
<Window.Resources>
I ignored this – and just copied everything between the head (left out) and the closing
</UserControl>
to my WPF XAML. Of course the thing looked bad for the moment. Next I hit CTRL+H and replaced UserControl. with Window.
Looked good – the designer displays what I saw in Silverlight – so I gave it a build.
ERROR the handler for btnTest_Click is missing – no problem – next I planned to copy the code which should solve this problem.
So I copied the code and removed a few things:
- The Handler for “UserControl_Loaded” (this set the background color from parameters – no longer needed.
- The handlers and attributes for HTML communication
- And finally I had to change the constructor
The Silverlight Control created the Service Address there from the “Current.Host”. WPF (as standalone app) has no host.
But it should also provide an easy way for the situation when the service address changes.
I choose to use a setting for this – so my constructor looks like this:
public Window1() {
//and build an endpointaddress -- Use properties here
m_epaServiceAddress = new EndpointAddress(Properties.Settings.Default.ServiceAddress);
}
So after removing a few line of code and changing this one line it looked good to me.
I gave it a try – BINGO – it runs. Here is how it looks – next to it’s Silverlight counterpart:
How long does it take me to do this? I didn’t take too much care – but I guess about 15 Minutes for sure not longer.
I think the telerik promise with “ensures complete code reusability” is more than kept.
Of course WPF has no HTML scripting interface – and I didn’t take any care when I create my Silverlight control – so it took a little time to remove the (a bit spread) code.
But finally I could say the only thing to “recode” was the retrieval of the web service address.
Or in other words – one single line of code.
If you did not read the whole series – start here so that you know what’s going on.