Click here to Skip to main content
15,905,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hy guys, can You help me on this?

I'm using Silverlight 4 and VS 2010.

I've created a very simple UserControl named "Marquee".
	xmlns:mc="" x:Name="userControl"
	d:DesignWidth="1125" d:DesignHeight="30">

	<grid x:name="LayoutRoot" xmlns:x="#unknown">
		<canvas x:name="MarqueeContainer" margin="0" util:clip.tobounds="true" xmlns:util="#unknown">
			<stackpanel x:name="MarqueeContent" d:layoutoverrides="VerticalMargin" orientation="Horizontal" canvas.left="0" height="30" loaded="MarqueeContent_Loaded" xmlns:d="#unknown" />

In my MainPage I've inserted the user control "Marquee1" and set it's background property.
<grid x:name="LayoutRoot" xmlns:x="#unknown">
    <mrq:marquee x:name="Marquee1" height="30" verticalalignment="Top" margin="148,0,413,0" removed="#FFC8DC1A" xmlns:mrq="#unknown" />
    <Button Content="Button" Height="30" HorizontalAlignment="Left" Margin="393,134,0,0" x:Name="button1" VerticalAlignment="Top" Width="219" Click="button1_Click" />

(Somehow I can't paste the code as it was on VS. Where it say "removed" it should be "background" on the mrq:Maquee element and the xmlns:mrq="#unknown" additions are strange to me.)

What I need is to bind the canvas "MarqueeContainer" background in the usercontrol "Marquee" to the "Marquee1" background property set on the MainPage.

In the usercontrol XAML It has to be something like:
Background="{Binding ???????}

But I'm kind of lost!
Updated 30-Oct-11 4:22am

I have found a workaround in C# to be placed in the Loaded event of the usercontrol:
MarqueeContainer.Background = ((Marquee)LayoutRoot.Parent).Background;

It works ... but I think that XAML would be the place to be.
Share this answer
You could use element to element binding.

Background = "{Binding Background, ElementName=LayoutRoot}"

LayouRoot being the grid of your application in this instance.
Share this answer
Allmost there Kelvin, thanks.

Got it working with:
Background="{Binding Background, ElementName=userControl}"
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900