Silverlight

IIS 7, Silverlight Pivot: Handler "CXML" has a bad module "ManagedPipelineHandler" in its module list

This is a problem that one keeps running into if one gets to install projects with Silverlight Pivot often enough that you remember the problems, yet not often enough to remember the solutions.

This is how I solved the problem

Set up Application pool settings correctly
* I had to go to Application Pools, find the site pool, and double click it.
* Change .NET version to v4.0
* Make sure that Managed pipeline mode is set to Integrated

Register .NET

* %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

http://forums.silverlight.net/t/189941.aspx/1

Silverlight, TabControl: How to set tab focus programmatically from user controls

Photobucket

For some reason, when we built an silverlight app, we didn't use the navigation and page controls. Instead, we have a single page with a border. This border swaps what would have been pages, which are controls containing tab controls. These tab controls themselves contain other user controls. Everything has worked out fine until now, when the need to link between these tabs arose.

The problem: I need to have a link from one tab content that will take me to another one. The tab content is itself another user control.

The solution:

I rejected traversing the tree because I thought it was fragile. Adding one border can break the code. Instead I created an App public member. May not be the prettiest solution, but it sure is the shortest that works.

The steps:
1. Go to App.xaml.cs, and add your new member

    public partial class App : Application
    {
        public TabControl MainPageTab;  // New member type TabControl for which we need to set TabItem focus 
   ....

2. In your user control, add the code that will set focus on the target TabItem in the Button_Click() method

        private void ToHome_Click(object sender, RoutedEventArgs e)
        {
            var app = (App)App.Current;                                                                  //get the current app
            var home = (TabItem)app.MainPageTab.FindName("tabHome");  // get the target TabItem
 
            app.MainPageTab.SelectedItem = home;                                     // Set focus via setting SelectedItem
        }

Again, using page controls may be a better practice, but this technique is useful in scenarios where apps were built without using pages, and you need to navigate through tabs. It gets the job done in a more robust manner than navigating the control tree would have done.

Silverlight: DataContext Bindings not working in XAML

Photobucket
This is a very short one. I hope it will save you time:

XAML BINDINGS ONLY WORK WITH PROPERTIES!!!

It won't with object variables, even if they are public.

Silverlight: using borders

One would think that this would be easy, but it isn't.

If one come from a html/css background, you just expect that silverlight will work with a box model. However, it doesn't. Each element has a margin, but you can't produce a border around the elements. For that, you will need a Border element. No big deal. You just put that baby around your element, let's say, an image, and you are done, right?

Wrong.

Let's say you have this grid structure:

   <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            &lt;RowDefinition Height="300"&gt;</RowDefinition>
            &lt;RowDefinition Height="70"&gt;</RowDefinition>
            &lt;RowDefinition Height="30*" /&gt;
        &lt;/Grid.RowDefinitions&gt;
        &lt;Grid.ColumnDefinitions&gt;
            &lt;ColumnDefinition Width="500"&gt;</ColumnDefinition>
            &lt;ColumnDefinition Width="500"&gt;</ColumnDefinition>
        &lt;/Grid.ColumnDefinitions&gt;
&lt;Image Source="cutebunnies.jpeg" Grid.Row="0" Grid.Column="1" Width="475" Height="300" Canvas.Top="0"  Name="imageBase" Stretch="Fill" Margin="0,0,0,0" MouseLeftButtonDown="imageBase_MouseLeftButtonDown" /&gt;

Okay, now we are ready to add our border. First step, you but the border tags around the Image tag:

&lt;Border&gt;
  &lt;Image Source="cutebunnies.jpeg" Grid.Row="0" Grid.Column="1" Width="475" Height="300" Canvas.Top="0"  Name="imageBase" Stretch="Fill" Margin="12,2,45,5" MouseLeftButtonDown="imageBase_MouseLeftButtonDown" /&gt;
&lt;/Border&gt;

In my mind, this should work. In your mind, you may think that it works too. It doesn't.

When you run it, you don't see a border. And your previous layout is probably messed up. The first step to fixing this is to give attributes to the border element:

&lt;Border   BorderBrush="Blue" BorderThickness="4"&gt; 
  &lt;Image Source="cutebunnies.jpeg" Grid.Row="0" Grid.Column="1" Width="475" Height="300" Canvas.Top="0"  Name="imageBase" Stretch="Fill" Margin="12,2,45,5" MouseLeftButtonDown="imageBase_MouseLeftButtonDown" /&gt;
&lt;/Border&gt;

The next step into fixing this is to move the grid attributes from the Image element to the border element. This will take care of the problem with the weird layout problems.

&lt;Border Grid.Row="0" Grid.Column="1"&gt;
  &lt;Image Source="cutebunnies.jpeg" Grid.Row="0" Grid.Column="1" Width="475" Height="300" Canvas.Top="0"  Name="imageBase" Stretch="Fill" Margin="12,2,45,5" MouseLeftButtonDown="imageBase_MouseLeftButtonDown" /&gt;
&lt;/Border&gt;

At this point you may see that the image is sort of inside of it, but it may still miss part of the image? What is going on? Well, if you moved the image in the designer area, it may have included the Margin attribute in the Image element. Set those values to zero or whatever you actually want them to be. Now it should look like this, and it should work correctly.

&lt;Border Grid.Row="0" Grid.Column="1"&gt;
  &lt;Image Source="cutebunnies.jpeg" Grid.Row="0" Grid.Column="1" Width="475" Height="300" Canvas.Top="0"  Name="imageBase" Stretch="Fill" Margin="0,0,0,0" MouseLeftButtonDown="imageBase_MouseLeftButtonDown" /&gt;
&lt;/Border&gt;

Silverlight: HtmlPage_NotEnabled

I have been working on a silverlight project recently, so I got a lot of little nibbles of wisdom on this technology. Unfortunately I am very busy for the next few weeks, so I won't get to share them with readership, which mainly consists of myself (and as a reader, I just love the good quantities of great tips and information this blog provides to me.).

In any case, the weird silverlight issue of the moment:

I am working on a custom control, and then, after I did something to it, the design mode breaks. The behavior of the control is fine while I am running it; it just messes design mode big time. And it gives me an error about how the instance couldn't be created. Searching for the error message is fruitless since it seems that many things can happen to make xaml choke.

Then the message told me about how I should search at some Key Value stuff. I look towards the end of the main error, and this is what I get:

HtmlPage_NotEnabled

Which happens when you are calling on the Browser object, such as when you need to get the root url of the site.

The solution is to use the following check:

  using System.ComponentModel;
 
            if (!DesignerProperties.GetIsInDesignMode(this))
                PopulateTree();

For the full explanation, go to the site below. Thanks, Andy :)
http://www.andybeaulieu.com/Home/tabid/67/BlogDate/2009-06-30/Default.aspx

Syndicate content