CodeDrop 5 Binding RegionName in xaml

Nov 14, 2008 at 5:43 PM

Not sure if you are aware of this issue... but when binding to RegionName in xaml the Unity throws unresolved exception.

I was able to re-produce this in VisualCompostion/TopDownUIComposition code drop 5 sample. In this sample the desktop version is using the binding to object string, whereas in silverlight target, this is directly typed in xaml.

<ItemsControl cal:RegionManager.RegionName="{x:Static infrastructure:RegionNames.MainRegion}" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<ItemsControl cal:RegionManager.RegionName="MainRegion" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>

If you try to bind in Silverlight the RegionName at xaml to string similarily, the application throws Unity target type unresolved exception.

Nov 15, 2008 at 12:54 PM
Silverlight does not support binding against static members. That's why the Silverlight sample uses a string property rather than a binding expression.
Nov 15, 2008 at 1:35 PM
Edited Nov 15, 2008 at 2:40 PM

It is correct that x:static does not exist in SL2 and its not supported. However SL2 does support to use binding expression to CLR object and its properties.

I am binding by expression all XAML string values to resource properties on SL2WithPrism CodePlex project.
For example, following works fine and you could just use any of CLR class and its properties (public const string or public static string) rather than resource class generated property

In shortly, the code taken from SL2WithPrism you could realize this by:

1. Define your namespace in xaml (From SL2WithPrism/Shell example)

2. Create a known resource name (from SL2WithPrism/Shell example)
<loc:Resources x:Name="LocalizedStrings"/>

3. Bind directly to your resource name key in xaml (From SL2WithPrism/Shell example)
<TextBlock HorizontalAlignment="Left" Margin="25,20,0,0" Width="Auto" Text="{Binding tblk_SiteName_Text, Source={StaticResource LocalizedStrings}}"  FontWeight="Bold" Foreground="#FFFFFFFF" FontSize="18" FontFamily="Corbel"/>

If I try to use same approach to RegionName then Unity will throw type unresolved exception.

In quick look, I saw that binding expression was in the string rather than actual value and Unity was trying to resolve this expression and failed.

But I haven’t had a time yet to see where it goes wrong exactly but I think it’s a bug. And this is also the reason I created this thread.

I am sorry that I wasn’t clear enough in first shot of this thread but I hope this describes the issue/bug better related to RegionManager and binding expression.