Lubo Blagoev's Blog

My thoughts on software and technology

What's new from MIX08


Microsoft made a ton of announcements at MIX08. I just watched Scott Guthrie at the opening key note. He talked about so many things that I didn't remember them all after I finished watching the movie, so I decided to try summarize them here:

  • Just Released .NET 3.5, VS2008, IIS7, Windows Server 2008. - I don't know what that means since I am using these for a couple of months now. Well except Longhorn 2008. I think they don't count the MSDN subscription downloads.
  • ASP.NET MVC, ASPNET AJAX updated, ASPNET Dynamic Data framework. - Well not yet. Scheduled for "Late this year". I expect this to be this summer since they are talking about couple of releases in that timeframe. Preview releases are available right now though.
  • IE8 beta 1.
    • CSS 2.1 support at the final IE8 release.
    • CSS Certification. They have submitted 702 test cases to W3C test group available at MSDN under BSD license.
    • Performance. vlcsnap-5397866That's one of the reasons why I switched to Firefox. It is interesting why we don't see these kind of comparisons from Microsoft when they release a new product but we see them just when they are releasing the next version of this exact same product. To tell you the through IE 8 beta 1 is more slower than IE7. But hey its a beta 1 remember?

 

 

 

 

 

    • HTML 5 Support.
      • Better history(Back button) support for AJAX sites through HTML 5 hash functionality.
      • Network aware sites through connection events.
      • DOM storage. Save pages locally temporary.
    • IE developer tools, - Updated. Yeah Firefox has couple of them right now.
    • WebSlices - Subscribe to a web page part in IE8. For this to work web sites should specify couple of CSS styles to a div.WebSlices specification is available right now through Open Specification Promise. Samples are also available.
  • Silverlight 2 beta  1 available right now. - I installed that immediately. Like the 1,5+ million others do per day.
    • Rich High Def Video.
    • Adaptive Streaming. Silverlight monitors network bandwidth and automatically adjusts the quality of the video. Very good. I don't know if all those flash video players support that, but in any case this is a must have functionality. Moreover you can plug-in your own algorithm for stream adjustment into the media system.
    • Windows Media Services 2008 for Windows Server 2008 - 3x faster, free and already proved to work in real world scenarios.
    • IIS7 media pack. - Shipped already. Throttling media buffering download to be only seconds ahead of the current video position.
    • Advertising. Making money from your site.
      • Silverlight ad template. A wizard for creating advertising for you to include in web pages.
      • Atlas AdManager. Manage and track your advertising campaign. Many tracking information. Most importantly how much of the video the user have watched. They call it Engagements. Very detailed really.
      • Expression Media Encoder 2. Visually add marker points for dynamically load ads over the video. Very good non intrusion way to show advertisements as overlays on the video the user is watching. XAML overlays also supported.
    • NBC Olympics web site is going to be great. - The main issue was that they have less than 150 days to finish it.
    • Multilingual support JavaScript, VB, C#, IronPython, IronRubby.
    • WPF UI framework support. Layout management. Databinding, Skins and Styles and Animations.
    • Networking stacks. REST, SOAP, WS-*, HTTP endpoints, Cross Domain Networking, Raw Sockets support.
    • Linq query support.
    • Local cache support. That is interesting. Maybe SQL Compact for Silverlight?
    • Higher performance.
    • Small download 4,3MB.
    • Microsoft is partnering with Novel to deliver Linux support for Silverlight. That is great. Most probably it will kill Moonlight project.
    • Built in Controls. Available as open source. You can modify them as you see fit. Available already.
    • Testing framework for UI controls and for non UI code. 2000 unit tests. Available already as open source.
    • Visual Studio 2008 Tools for Silverlight Beta 1 and Expression Blend 2.5 March Preview support. These Expression tools will never come out of beta. Don't you think?
    • Silverlight Deep Zoom functionality available for you to use it on your web sites. See it in action on Hard Rock Memorabilia.
    • SharePoint Silverlight extensions. Yeah! I am very excited about this specifically, cause man that software will really survive the sun apocalypse. In fact I think this Silverlight thing was invented for this in the first place.wink
    • Mobile devices support. That's huge. How in the world we are going to catch up with iPhone without this.
    • Silverlight support on Nokia Symbian S60, S40 and Internet Tablets OS. That's fantastic news! Do you remember the Silverlight's code name? WPF Everywhere anyone? Now what Nokia needs is a nice Singularity OS for mobile devices to get rid of the Symbian+Java crap running on in.
  • WPF improvements.
    • More controls.
    • Streamlined .NET setup. .NET 3.5 is installed by default on Windows Server 2008 but is not installed by Vista SP1 setup.
    • Startup performance.
    • Graphics Improvements. Offload more onto the GPU. - Will be available as a summer update.
    • Custom graphics effects. Onto the GPU also. Custom effects for you to implement. Over pictures, movies and controls.

That is a very long list of announcements. There are at least 15 things I want to test right now but I know I will skip it. As always the time that we have is very limited. The next set of Betas and CTPs are coming very soon. That's how's live on the verge of technology.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Workaround for using WPF PageFunctions in Expression Blend


PageFunctions are very interesting concept of WPF. If you want to use some kind of a navigation in your applications you will definitely have a scenario where you want to redirect the user to a page where to ask for some input and after that receive that in the previous page. This is where PageFunction can be used. It works the same as a normal functions. You call a function passing some parameters and expect a specific type of result. PageFunction<T> essentially allows you to treat a page navigation like a function call, in which a page navigates to (calls) a page function and expect a return result.

Though it is ok to use these types of functions in Visual Studio 2008, in Expression Blend you receive  these errors when you try to open a PageFunction in the designer:

The name "PageFunction" does not exist in the namespace
"http://schemas.microsoft.com/winfx/2006/xaml/presentation".

The property "TypeArguments" does not exist in the 
"http://schemas.microsoft.com/winfx/2006/xaml" namespace.

 

Recently Microsoft released Expression Blend 1 SP1 and Blend 2 December Preview. I was curious if these new builds supports page functions and I have posted a question on the forums (link). Interestingly enough I received answers that PageFunctions are not even supported in Blend v2. WHAT THE...? Man I can't wait till v4. I guess many of you either. One thing caught my eye on the experts answers:

No, we don't plan to support generics at the root of markup (of which
PageFunction<T> is an example) in version 2 either.

 

Well no support for generics at the root of xaml markup. If this is the problem can we workaround it? That's the million dollar question don't you think. The answer is YES we can. Below I will show you how.

First you need to have a PageFunction in your project. If you do not have one use Visual Studio and Add New Item to add new PageFunction with meaningful name. This is how xaml looks like by default. Expression Blend have a problem with this "x:TypeArguments" attribute and the with the root element "PageFunction"

<PageFunction
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    x:Class="UntitledProject1.SelectUserNamePageFunction"
    x:TypeArguments="sys:String"
    Title="SelectUserNamePageFunction">
  <Grid>

  </Grid>
</PageFunction>

 

Depending on what name you choused for the page function you will have a code behind class created for it. I have SelectUserNamePageFunction.xaml.cs file which look like
 
namespace UntitledProject1
{
    /// <summary>
    /// Interaction logic for SelectUserNamePageFunction.xaml
    /// </summary>
    public partial class SelectUserNamePageFunction : SelectUserNamePageFuncitonBase
    {
        public SelectUserNamePageFunction()
        {
            InitializeComponent();
        }
    }
}
 
 
What we need to do is add one more class in the hierarchy and make SelectUserNamePageFunction derive from it. Just add a SelectUserNamePageFunctionBase class below the one that we have already created. This will simplify its removal after we have proper PageFunction support in future Blend versions. It is very important to have the SelectUserNamePageFunction class at the top the the namespace since the Visual Studio WPF Designer (Cider) will not be able to add event handlers and will complain about it.
 
namespace UntitledProject1
{
    /// <summary>
    /// Interaction logic for SelectUserNamePageFunction.xaml
    /// </summary>
    public partial class SelectUserNamePageFunction : SelectUserNamePageFuncitonBase
    {
        public SelectUserNamePageFunction()
        {
            InitializeComponent();
        }
    }       public class SelectUserNamePageFuncitonBase : PageFunction<string> { } 
}
   
Select the SelectUserNamePageFunction.xaml file in Solution Explorer and change the Custom Tool Namespace property to "UntitledProject1" since this is our namespace.
 
 image_2
 
Change the xaml file. Add the crl-namespace:UntitledProject named z. Change the xaml root element to z:SelectUserNamePageFuncitonBase. The final file look like:
 
<z:SelectUserNamePageFuncitonBase
    xmlns:z="clr-namespace:UntitledProject1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    x:Class="UntitledProject1.SelectUserNamePageFunction"
    Title="SelectUserNamePageFunction">
  <Grid>

  </Grid>
</z:SelectUserNamePageFuncitonBase>
 
That's all. Now you can open this SelectUserNamePageFunciton.xaml in Blend and edit it just like any other Page.
 
Download the sample solution UntitledProject1.zip

Happy coding!

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

December 8, 2007 20:03 by lubo
Tags: , ,
Categories:

Building a WPF LinkLabel control


Currently there is no LinkLabel control for WPF and that's why I decided to build one. First I will show what is currently available in WPF.

If you want to simulate LinkLabel you can use inline Hyperlink in a TextBlock.

 
<TextBlock>
    <Hyperlink>
        <Run Text="Test link"/>
    </Hyperlink>
</TextBlock>
 
You can use Label control and inline there a hyperlink but I think TextBlock is better since you can edit the properties of all the child elements from InlineCollection directly in Expression Blend UI.

 

  WPF LinkLabel 1

While this approach have benefits I don't like it much so I though why not write a better LinkLabel control similar to the one in Windows Forms. And so I did. First let me show you what the control looks like.

 A WPF LinkLabel

The first one is a default LinkLabel control, the second one have its  LinkLabelBehavior set to HoverUnderline and the third is using custom colors for Foreground and HoverForeground properties.

The LinkLabel control supports

  • Foreground and HoverForeground properties
    • Allows setting custom properties of both foreground and hoverforeground properties
  • LinkLabelBehavior property
    • Allows setting the underline behavior when cursor hovers or not the LinkLabel
  • Custom HyperlinkStyle property
    • You can use this property to set specific custom defined style for the internal hyperlink of the LinkLabel. If set override custom  foreground and hoverforeground colors
  • Url - the navigation target property.
  • All other properties are inherited from the standard System.Windows.Controls.Label control

Settings these properties is easy using Blend or xaml code.  

<ThemedControlLibrary:LinkLabel Content="Link Label" FontSize="22"/>
<ThemedControlLibrary:LinkLabel Content="Link Label" LinkLabelBehavour="HoverUnderline" />
<ThemedControlLibrary:LinkLabel Foreground="#FF847901" HoverForeground="#FF06C8F2" Content="Link Label" LinkLabelBehavour="NeverUnderline"/>

 

WPF LinkLabel

Here is how this control can be used in a window. Just add namespace to the xaml and use the control.

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="DemoApplication.Window1"
    Title="DemoApplication" Height="300" Width="300"
    xmlns:ThemedControlsLibrary="clr-namespace:ThemedControlsLibrary;assembly=ThemedControlsLibrary"
    >
    <Grid>
        <ThemedControlsLibrary:LinkLabel HorizontalAlignment="Left" VerticalAlignment="Top" Content="LinkLabel"/>
    </Grid>
</Window>

 

The whole code of the control as simple as it can be. It just defines the desired properties and the appropriate category attributes that control where these properties are shown in Blend Designer.

public class LinkLabel : Label
{
    private const string _linkLabel = "LinkLabel";

    public static readonly DependencyProperty UrlProperty = DependencyProperty.Register("Url", typeof(Uri), typeof(LinkLabel));

    [Category("Common Properties"), Bindable(true)]
    public Uri Url
    {
        get { return GetValue(UrlProperty) as Uri; }
        set { SetValue(UrlProperty, value); }
    }

    public static readonly DependencyProperty HyperlinkStyleProperty = DependencyProperty.Register("HyperlinkStyle", typeof(Style),
            typeof(LinkLabel));

    public Style HyperlinkStyle
    {
        get { return GetValue(HyperlinkStyleProperty) as Style; }
        set { SetValue(HyperlinkStyleProperty, value); }
    }

    public static readonly DependencyProperty HoverForegroundProperty = DependencyProperty.Register("HoverForeground", typeof(Brush),
            typeof(LinkLabel));

    [Category("Brushes"), Bindable(true)]
    public Brush HoverForeground
    {
        get { return GetValue(HoverForegroundProperty) as Brush; }
        set { SetValue(HoverForegroundProperty, value); }
    }

    public static readonly DependencyProperty LinkLabelBehavourProperty = DependencyProperty.Register("LinkLabelBehavour",
            typeof(LinkLabelBehaviour),
            typeof(LinkLabel));

    [Category("Common Properties"), Bindable(true)]
    public LinkLabelBehaviour LinkLabelBehavour
    {
        get { return (LinkLabelBehaviour)GetValue(LinkLabelBehavourProperty); }
        set { SetValue(LinkLabelBehavourProperty, value); }
    }

    static LinkLabel()
    {
        FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(
            typeof(LinkLabel),
            new FrameworkPropertyMetadata(typeof(LinkLabel)));
    }
}

 

In order for the Content to be bindable I used the BindableRun implemented by Filipe Fortes here. I added this BindableRun object to the control template like so:

<local:BindableRun BoundText="{Binding RelativeSource= {RelativeSource TemplatedParent}, Path=Content}"/>	
 
In order to have theme support  for any control you should have a Themes folder in the project that contains the Styles of your control. The LinkLabel defines only one such file Generic.xaml since the hyperlink style is the same no matter what is the current system theme. I will not include the control template of the LinkLabel but it consist of a inline Hyperlink in a TextBlock just like you may have done it with out the LinkLabel control. Check it in the attached project.
That's all about it. Simple and beautiful. Download and use it.
 
[Update 25.11.2007] Fixed the RequestEvent and ClickEvent registration and firing.
[Update 10.11.2007] I have updated the control to include WPF commands support and fixed IsEnabled property behavior.
 

Download the source code Themed Controls Library.zip or just the compiled assembly ThemedControlsLibrary.dll

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

November 10, 2007 17:29 by lubo
Tags: , ,
Categories: