{x:Static infrastructure:RegionNames.ContentRegion} in Silverlight

Dec 16, 2008 at 6:03 AM
I think {x:Static is not supported in Silverlight. So, What would be the workaround for that? I don't like to hard-code the region name in XAML. 
Dec 16, 2008 at 12:58 PM
Edited Dec 16, 2008 at 1:26 PM


There is a way as CLR objects binding are supported in Silverlight 2. I uploaded SL2WithPrism CodeDrop 2 refresh into URL below, you can download the whole solution and examine it.

Please note that when you binding to RegionManager.RegionName you will get design time error AG_E_PARSER_BAD_PROPERTY_VALUE but this do not affect runtime at all. I started to get this runtime error after code drop 7, and I get this error also when I am typing RegionName in XAML like RegionManager.RegionName=”PlaaPlaaRegion”.  I think this is a bug as I get this design time error on original code drop 7 samples as well. I raised this error in here, as there is noway in current version of Silverlight test framework to detect this type of design time errors so I guess they are not tested; anyhow I have not get confirmation for this behavior yet. You only get this design time error on RegionManager class not in other components even if you use same supported CLR object binding apporach. 

If this design time error does not bother you now, see the approach below and link to sample solution that uses this. I did not place this solution yet to http://www.codeplex.com/SL2WithPrism site as I am in process of refactoring it and adding more functional parts for it.

In this sample, I am directly binding TextBox, Button text properties by XAML to Resources.resx that are static and located at Properties in SL2WithPrism project and SL2WithPrism.Module.Authentication project. I do this by using the following XAML (which does not create design time error):
Content="{Binding btn_LogOut_Text, Source={StaticResource LocalizedStrings}}"

I am also doing same way and binding the RegionName by using the following statement: (which creates design time error but works fine in runtime)  Regions:RegionManager.RegionName="{Binding MiddleRightRegion,Source={StaticResource CommonRegions}}"

I am linking above StaticResources to classes by defining them in UserControl XAML


<common:Regions x:Name="CommonRegions"/>
<loc:Resources x:Name="LocalizedStrings"/>

If you re-run the resources by the resource tool, you will get the Resource class regenerated, which will make by default the Resource class Internal. If you want to bind from Resources.resx by using XAML you need to change the generated Resource class declaration from Internal to Public. See the SL2WithPrism discussion


You can download working version from below link: http://www.xentree.com/SL2WithPrism/SL2WithPrism_Code_Drop_2.zip  

Hope above helps…