views:

915

answers:

2

How does one embed the Silverlight ProgressBar control in a a custom splash screen? I put the following into loose xaml (simplified for brevity):

<Grid xmlns="http://schemas.microsoft.com/client/2007"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
      <ProgressBar />
</Grid>

The error message is as follows: Error: Unhandled Error in Silverlight Application Code: 2007
Category: ParserError
Message: Unknown element: ProgressBar.
etc

Isn't the ProgressBar a standard control defined in the http://schemas.microsoft.com/winfx/2006/xaml/presentation namespace?

A: 

I'm assuming SL2 or SL3 since the presence of a progress bar - it got added in SL2.

The /winfx/2006/xaml/presentation name space isn't declared - but certainly in SL2/3 that is where it resides. You have used the alternative http://schemas.microsoft.com/client/2007, this is a legacy namespace for SL1.0

The code given will work, but to reproduce I have to have the root element as a user control and the namespaces have to reside in there, otherwise the usercontrol tag itself is not recognised.

<UserControl x:Class="myApp.scratchpad"
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
       <ProgressBar />
    </Grid>
</UserControl>

Worked fine in SL3.

Can you post more of the page, root element, update the reference to the SL2/3 namespace and also say which verison of SL is being used?

Andrew
Putting it into a UserControl at the root was the key to getting it to work. I pasted your example and it worked fine.
David in Dakota
A: 

If this is for the SplashScreenSource property of the object tag, then the XAML must be Silverlight 1+JavaScript (non-managed XAML) Here is how you would do that: (Taken from the Silverlight SDK here)

<Canvas Background="Black" Width="302" Height="52">
    <Rectangle Canvas.Left="1" Canvas.Top="1" Width="300" Height="30" Fill="White"/>
    <Rectangle x:Name="progressBarFill" Canvas.Left="1" Canvas.Top="1" Height="30" Fill="Blue"/>
</Canvas>

And then use a JS function to update the progress:

function onProgressChanged(sender, eventArgs)
{
    var slPlugin = sender.getHost();
    slPlugin.content.findName("progressBarFill").width = eventArgs.progress * 300;
}
Michael S. Scherotter