silverlight

After moving some files my Windows Phone Project Throws a XamlParseException


I am not sure if this is an known issue for Microsoft, but at least I am aware of this. However this is the first time I am gonna document it. Since it can be very frustrating

The Problem

I want to reorganize the files in my Windows Phone Project in order to follow our implementation of MVVM, moreover we have decided that resx file will live in their own assembly project. However, once I move the Resource file to an external assembly the application just thrown an XamlParseException even though the reference in XAML is totally correct.

REMARKS
XamlParseExceptions may be thrown by other reasons. It is important to realize that I knew I moved the RESX file to a different assembly and before that everything was working. Certainly I updated the reference to the new assembly, and the exception was still being thrown. That is why this is a tricky issue.

The solution

It took some time to me to noticed, but somehow the project that contains the RESX file cannot contain a dot (.) character in its assembly name. If it happens then XAML parse will throw a XamlParserException even though the reference to the assembly is correct. The error message may contain something like this:

System.Windows.Markup.XamlParseException occurred
  HResult=-2146233087
  Message=Unknown parser error: Scanner 2147500037. [Line: 10 Position: 126]
  Source=System.Windows
  LineNumber=10
  LinePosition=126
  StackTrace:
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at MyApp.App.InitializeComponent()
       at MyApp.App..ctor()
  InnerException: 

Taking a look at the location where I was loading the Resource it was this:

<Application
    x:Class="MyApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">

    <!--Application Resources-->
    <Application.Resources>
        <local:LocalizedStrings xmlns:local="clr-namespace:MyApp;assembly=MyApp.WindowsPhone8.Resources" x:Key="LocalizedStrings"/>
    </Application.Resources>

    <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService
            Launching="Application_Launching" Closing="Application_Closing"
            Activated="Application_Activated" Deactivated="Application_Deactivated"/>
    </Application.ApplicationLifetimeObjects>

</Application>

The line one of my projects generates an assembly named: ‘MyApp.WindowsPhone8.Resources’, in order to resolve the issue I only have to update the generated assembly name to be ‘MyApp_WindowsPhone8_Resources’ and then update the proper reference in the XAML. For example:

        <local:LocalizedStrings xmlns:local="clr-namespace:MyApp;assembly=MyApp_WindowsPhone8_Resources" x:Key="LocalizedStrings"/>

After performing this change your app should work normally.

Pivot ( or Panorama ) Index Indicator


Hello,

The Problem:

Creating a pivot (or panorama) indicator could be a challenging task. The control should:

  • Indicate in which item of the collection you are looking at
  • Let you tap on a given item and navigate in the panorama to that given item
  • Let you customize the look and feel of the items.

The Solution: A Second thought

Sounds like the perfect scenario for a custom control, and in some of the cases it is. However, after some minutes thinking about this idea, I realized that the ListBox supports most of these requirements but only one pending task: it has to interact properly with the Panorama or Pivot.  Thus, the current solution uses a ListBox (Custom Styles and Templates) for modifying the look and file, and prepares a behavior (more specifically a TargetedTriggeredAction<T1,T2> ) for letting the ListBox interact with a index based collection (e.g. Pivot, Panorama, ListBox, etc … ).

A behavior …  (What’s that?)

Well with XAML a bunch of new concepts arrived to .NET development world. One in particular which is very useful is a behavior . You can think about a behavior like a encapsulated functionality that can be reused on different context under the same type of items.  The most popular behavior i guess it is EventToCommand which can be applied to any FrameworkElement and it maps the Loaded Event to a Command when implementing a View Model.

Thus, since We have a ListBox already in place, we only want it to behave synchronized with a Pivot or Panorama. Thus, the external control will be a parameter for our behavior.

    [TypeConstraint(typeof(Selector))]
    public class SetSelectedItemAction : TargetedTriggerAction
    {
        private Selector _selector;

        protected override void OnAttached()
        {
            base.OnAttached();

            _selector = AssociatedObject as Selector;
            if (_selector == null)
                return;
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            if (_selector == null)
                return;
            _selector = null;
        }

        protected override void Invoke(object parameter)
        {
            if (_selector == null)
                return;

            if (Target is Panorama)
                InvokeOnPanorama(Target as Panorama);
            if (Target is Pivot)
                InvokeOnPivot(Target as Pivot);
            if (Target is Selector)
                InvokeOnSelector(Target as Selector);
        }

        private void InvokeOnSelector(Selector selector)
        {
            if (selector == null)
                return;
            selector.SelectedIndex = _selector.SelectedIndex;
        }

        private void InvokeOnPivot(Pivot pivot)
        {
            if (pivot == null)
                return;
            pivot.SelectedIndex = _selector.SelectedIndex;
        }

        private void InvokeOnPanorama(Panorama panorama)
        {
            if (panorama == null)
                return;
            panorama.DefaultItem = panorama.Items[_selector.SelectedIndex];
        }

The idea is that you should be able to sync other elements by just dropping this behavior on a ListBox and setting up few properties, for example:

<ListBox
            x:Name="listbox"
			HorizontalAlignment="Stretch" Margin="12" VerticalAlignment="Top"
            SelectedIndex="{Binding SelectedIndex,ElementName=panorama,Mode=TwoWay}"
            ItemsSource="{Binding PanoramaItems}"
            ItemsPanel="{StaticResource HorizontalPanelTemplate}"
            ItemContainerStyle="{StaticResource ListBoxItemStyle1}"
            ItemTemplate="{StaticResource IndexIndicatorDataTemplate}"
            >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <local:SetSelectedItemAction TargetObject="{Binding ElementName=panorama}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </ListBox>

The behaviors can take more responsibility other than keep sync the selected item in one way. However my design decision was to use other mechanisms for keeping sync the indexes. (e.g. you could appreciate a TwoWay binding using SelectedIndex Property of the Target Pivot or Panorama).

Also, the ListBox has bound a list of items (empty items) just for being able to generate as much items as the Panorama has. This is other logic that may be moved to the behavior (however in my two previous attempts it didn’t work that well).

Here is the code sample, of this simple behavior and how ti keeps sync with the Panorama.

https://github.com/hmadrigal/playground-dotnet/tree/master/MsWinPhone.ParanoramaIndex

The following screenshot shows an indicator in the top/left corner where you can see the current tab of the Panorama that is being shown. Moreover, the user can tap on a given item to get directly to that selected tab.

Panorama_Index_Indicator

Cheers
Herb

Free ebook: Programming Windows Phone 7, by Charles Petzold


Hello

Certainly a platform is as strong as the tools that you can use on it. Microsoft is giving a lot of resources for developers in order to start producing in Windows Phone 7 (WP7). This time Microsoft Press book is giving a free ebook Programming Windows Phone 7 by Charles Petzold.

 

You can download it at Free ebook: Programming Windows Phone 7, by Charles Petzold

Best regards,
Herber

Free ebook: Programming Windows Phone 7, by Charles Petzold

Xhader 1.0 has been released!


Hello,

This is my first open source project that I’ve been published. It’s not based on my code, it’s based on a set of several tools and helpers I’ve been able to find in the web. So, the project itself is just a easy way to access all that resources in one single point by using your Microsoft Blend tool.

Xhader 1.0 Summary

Xaml is a markup language based on xml, which is used to create presentation layer in your Microsoft Application e.g. Silverlight Applications and WPF applications. There is a particular feature that is available for certain users which is to use the support to modify the rendere

See more information at:
Documentation

Download

Best regards,

Herber

Free ebooks from Microsoft Patterns and Practices


Hi,

I’ve collected some information about Microsoft free publications, and I think that they’re something people might be interested in. These ebooks are free and are updated by Microsoft Community (I think most of them from Patterns and Practices). So, the following is a list of the ebooks you will find from Microsoft:

Electronic books (ebooks)

Certainly there are many resources on when which are available to learn about development. Microsoft editorial for example they offer free ebooks from time to time. Microsoft Patterns and Practices also have some free ebooks available to download. Following are ebooks available for free:

Notes

  1. Microsoft Patterns and Practices is an constantly evolving project it’s possible see their progress at Microsoft Patterns and Practices Complete Catalogbacause of this it’s possible that the local version is outdated.
Cover Name Summary Source
Improving Web Services Security byMicrosoft Corporation Patterns and Practices This guide shows you how to make the most of WCF (Windows Communication Foundation). With end-to-end application scenarios, it shows you how to design and implement authentication and authorization in WCF. Learn how to improve the security of your WCF services through prescriptive guidance including guidelines, Q&A, practices at a glance, and step-by-step how tos. It’s a collaborative effort between patterns & practices, WCF team members, and industry experts. wcfsecurityguide at codeplex
Microsoft Application Architecture Guide, 2nd Edition byMicrosoft Corporation Patterns and Practices The guide is intended to help developers and solution architects design and build effective, high quality applications using the Microsoft platform and the .NET Framework more quickly and with less risk; it provides guidance for using architecture principles, design principles, and patterns that are tried and trusted. The guidance is presented in sections that correspond to major architecture and design focus points. It is designed to be used as a reference resource or to be read from beginning to end. Application Architecture Guide at MSDN
Performance Testing Guidance for Web Applications byMicrosoft Corporation Patterns and Practices This guide shows you an end-to-end approach for implementing performance testing. Whether you are new to performance testing, or looking for ways to improve your current performance testing approach, you will find insights that you can tailor for your specific scenarios. perftestingguide at codeplex

Performance Testing Guidance for Web Applications At MSDN

Team Development with Visual Studio Team Foundation Server by Microsoft Corporation Patterns and Practices This guide shows you how to make the most of Team Foundation Server. It starts with the end in mind, but shows you how to incrementally adopt TFS for your organization. It’s a collaborative effort between patterns & practices, Team System team members, and industry experts. tfsguide at codeplex

Team Development with Visual Studio Team Foundation Server at MSDN

Developers Guide to Microsoft Prism byMicrosoft Corporation Patterns and Practices Prism provides guidance designed to help you more easily design and build rich, flexible, and easy to maintain Windows Presentation Foundation (WPF) desktop applications and Silverlight Rich Internet Applications (RIAs) and Windows Phone 7 applications. Using design patterns that embody important architectural design principles, such as separation of concerns and loose coupling, Prism helps you to design and build applications using loosely coupled components that can evolve independently but which can be easily and seamlessly integrated into the overall application. Such applications are often referred to as composite applications. Developer’s Guide to Microsoft Prism at MSDN

Excuse me if I didn’t hosted the ebooks to download, instead I provide the original source link. I think it’s worthy to visit the site because  you are more likely to find the latest version, and visit their site is a good price to pay for a free ebook.

 

Best regards,

Herber

Windows Mobile Notes


Hi,

People from Coding4Fun (@ http://blogs.msdn.com/coding4fun/archive/2010/03/30/9987626.aspx )has sent this list of very nice resources to get started with Windows Mobile Phone Development.

A really nice link collection,

Herberth

Windows Mobile 7 Silverlight or XNA?


Hi,

You might be wondering why there are two programing models for Window Mobile 7. Well, it’s simple it’s because each model satisfy a different need.
The following link contains a table comparing general capabilities in both frameworks (XNA and Silverlight)
http://klucher.com/blog/silverlight-and-xna-framework-game-development-and-compatibility/

Regards,
Herberth

Microsoft book for Windows Mobile 7


Hi,

Microsoft press is giving a free preview of the Microsoft Book for Windows Mobile 7. Check it at:

Article (and download)
http://blogs.msdn.com/microsoft_press/archive/2010/03/15/free-ebook-programming-windows-phone-7-series-draft-preview.aspx

Online preview
http://docs.google.com/gview?url=http://download.microsoft.com/download/7/C/8/7C820C6F-C205-4ECF-B9F3-1505DD13F9BF/ProgWinPhonePreview.pdf

Getting started with Silverlight and Pixel Shader 02


Getting started with Silverlight and Pixel Shader 02

See an update about my project at http://wp.me/pIsCU-3e

I’ll continue this thread about my experience while I’m trying to create an installer for Expression Blend 3 for adding custom (pixel shader) effects. So let’s get started. First of all we need to write shaders… hm… I’m not really good writing pixel shaders I’ll be using the pixel shaders from http://wpffx.codeplex.com/ , unfortunately the last updated is based on the SL3 beta. If you want I’ll be indicating the updated source code so you can skip all this ‘update comments”. First I’ve download the ‘Mar 25 2009’ release.

Pre requisites:

Just check the first part @ https://hmadrigal.wordpress.com/2009/09/10/getting-started-with-silverlight-and-pixel-shader/

As far as I remember these products were installed when I started this journey.

  • Visual Studio 2008 SP1
  • Expression Blend 3
  • Silverlight SDK
  • Silverlight Toolkit
  • Shader Effects BuildTas Template

I think this last product requires XNA Framework SDK or Direct X SDK, however I’m not quite sure because of I have them already installed.

Getting the Windows Presentation Foundation Pixel Shader Effects Library
You can download the WPF FC  from codeplex at http://download.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=wpffx&DownloadId=63200&FileTime=128825198998100000&Build=15691 (please notices that I’m providing a link to a particular build, not the latest).  The project in http://www.codeplex.com is ‘Windows Presentation Foundation Pixel Shader Effects Library’ at http://wpffx.codeplex.com/. Once you have gotten the WPFFX and try to compile it. If it compiles then go ahead to the next section (where it’s the link to my CodePlex Project Xhader)

Trouble shouting  (the previous post also has some trouble shouting items).

The “ShaderBuildTask.PixelShaderCompile” task could not be loaded from the assembly ShaderBuildTask, Version=1.0.3072.18169, Culture=neutral, PublicKeyToken=44e467d1687af125. Could not load file or assembly ‘ShaderBuildTask, Version=1.0.3072.18169, Culture=neutral, PublicKeyToken=44e467d1687af125’ or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, and that the assembly and all its dependencies are available.

You will have to install the “Shader Effects BuildTask and Template”. The project is in codeplex at http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=14962 . Please read the readme file about how to install it appropriately. Also you will know how to create projects that uses pixel shaders.For additional information about this build task http://blogs.msdn.com/greg_schechter/archive/2008/08/11/a-visualstudio-buildtask-and-project-and-item-templates-for-writing-shadereffects.aspx

The type or namespace name ‘Theming’ does not exist in the namespace ‘System.Windows.Controls’ (are you missing an assembly reference?) MainPage.xaml.cs 13 31 SLEffectHarness

You will have to install the “Silverlight Toolkit”.I downloaded http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24246 (July 2009 release). Once It has been installed, you can copy the assemblies to a folder in your solution or use the assemblies in the default installation folder. The important thing here is to update the references.

The name ‘PixelFormats’ does not exist in the current context MainPage.xaml.cs 57 148 SLEffectHarness

Basically breaking changes for the SL3.3.19 WriteableBitmap changes The PixelFormat parameter for the WriteableBitmap constructor has been removed. WriteableBitmap(int pixelWidth, int pixelHeight, PixelFormat format) is now WriteableBitmap(int pixelWidth, int pixelHeight). The only supported PixelFormat is now Pbgra32.Similarly, the PixelFormat and PixelFormats type has been removed.Lock() and Unlock() have been removed.”From http://msdn.microsoft.com/en-us/library/cc645049%28VS.95%29.aspx

The tag ‘Expander’ does not exist in XML namespace ‘clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls’. MainPage.xaml 225 10 SLEffectHarness

The tag ‘Viewbox’ does not exist in XML namespace ‘clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls’. MainPage.xaml 314 13 SLEffectHarnessUpdate the namespace and assembly where the controls are stored.Add a reference to the dll ‘System.Windows.Controls.Toolkit.dll’.After xmlns:ctls=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls” Add the following namespace:xmlns:ctrlsToolkit=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit”Replace all the ‘ctls:Expander’ with ‘ctrlsToolkit:Expander’Replace all the ‘ctls:Viewbox’ with ‘ctrlsToolkit:Viewbox’Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.Parser Error Message: Could not load file or assembly ‘System.Web.Silverlight’ or one of its dependencies. The system cannot find the file specified.

If you run your web project and then this error comes up. To solve this, remove the Silverlight reference from the properties in your web project.  Then remove all the Silverlight pages, and JavaScript’s for Silverlight, and the ClientBin folder too. Then re add the silverlight project by using the silverlight tab in the web project properties.

At last set the ‘Start up page’.System.Windows.Markup.XamlParseException occurredMessage=”Invalid attribute value SearchMode for property Property. [Line: 5772 Position: 26]”LineNumber=5772LinePosition=26StackTrace:at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)at SLEffectHarness.App.InitializeComponent()at SLEffectHarness.App..ctor()InnerException:– OR –System.Windows.Markup.XamlParseException occurredMessage=”Invalid attribute value controls:Expander for property TargetType. [Line: 6281 Position: 45]”LineNumber=6281LinePosition=45StackTrace:at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)at SLEffectHarness.App.InitializeComponent()at SLEffectHarness.App..ctor()InnerException:XamlParserExceptions are thrown because of there are a couple of Xaml syntax outdated.Remove the setter tag for the ‘SearchMode’ property from the following files:…\WPFSLFx\WPFSLFx\SL\Demo_silverlight\SLEffectHarness\ShinyBlue.xaml(5772)…\WPFSLFx\WPFSLFx\SL\Demo_silverlight\SLEffectHarness\System.Windows.Controls.Theming.ShinyRed.xaml(5738)

Update namespace controls:Expander and controls:Viewbox. Remember first we need to add the ‘xmlns:ctrlsToolkit’ namespace, and then we replace the old namespace with this new one. These are the files:

  • …\WPFSLFx\WPFSLFx\SL\Demo_silverlight\SLEffectHarness\ShinyBlue.xaml(6281)
  • …\WPFSLFx\WPFSLFx\SL\Demo_silverlight\SLEffectHarness\ShinyBlue.xaml(6286)
  • …\WPFSLFx\WPFSLFx\SL\Demo_silverlight\SLEffectHarness\System.Windows.Controls.Theming.ShinyRed.xaml(5997)
  • …\WPFSLFx\WPFSLFx\SL\Demo_silverlight\SLEffectHarness\System.Windows.Controls.Theming.ShinyRed.xaml(6002)

Error: Unhandled Error in Silverlight ApplicationCode: 4004Category: ManagedRuntimeErrorMessage: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)at System.Windows.FrameworkElement.OnTreeParentUpdated(DependencyObject newParent, Boolean bIsNewParentAlive)at System.Windows.DependencyObject.UpdateTreeParent(IManagedPeer oldParent, IManagedPeer newParent, Boolean bIsNewParentAlive, Boolean keepReferenceToParent)at MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(IntPtr oldParentElement, IntPtr parentElement, IntPtr childElement, Byte bIsParentAlive, Byte bKeepReferenceToParent)Source File: http://localhost:36397/Default.htmlLine: 54

This is a very unusual exception. Unfortunately I haven’t been able to solve it. However I’ve noticed some scenarios that trigger this exception.Make sure you have installed Silverlight Runtime 3.0.40818.0 instead of 3.0.40624.0The error is very a constant in Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5 (.NET CLR 3.5.30729). Internet explorer and Chrome does not fail after updating Silverlight Runtime.If you run the application in ‘Release’, the issue is not triggered.

Error 6 The “PixelShaderCompile” task failed unexpectedly.System.NullReferenceException: Object reference not set to an instance of an object.at ShaderBuildTask.PixelShaderCompile.Execute()at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult) WPFTransitionEffects.csproj 139 5 WPFTransitionEffectsUnfortunately I don’t why this happens, it’s solved by closing and reopening the visual studio.

At this time the project should compile and you should be able to see the samples running. If you didn’t want to do all this work you might try to download my updated code from:

My code that sum up all this tricky work, my code has been posted at:

http://xhader.codeplex.com/

Regards,

Herberth