Skip to main content

Microsoft Silverlight

Unanswered Question Transparent BackgroundRSS Feed

(0)

ahlawy1983
ahlawy1983

Member

Member

20 points

6 Posts

Transparent Background

Hi
I want to do a silverlight control to work as a logo
I'll put some images and animation
but I want the main canvas to be transparent
I want the background of the host HTML page to be shown
Is that possible

y_makram
y_makram

Contributor

Contributor

6172 points

1,233 Posts

Re: Transparent Background

Yes this is possible. You need to set isWindowless property to true, set the silverlight control background to a color wit 0 alpha channel, and set the main canvas background to transparent. For details check this forum thread 

Thanks
Yasser Makram
http://www.silverlightrecipes.com
_____
Dont forget to click "Mark as Answer" on the post that helped you. If your question has not been answered, please post a followup question.

ahlawy1983
ahlawy1983

Member

Member

20 points

6 Posts

Re: Transparent Background

I have tried what you said but it is displayed with a black background
this my XAML code
<Canvas
    xmlns="http://schemas.microsoft.com/client/2007"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="100" Height="50" Canvas.Left="0" Canvas.Top="0"
     Background="Transparent"
    >

     <TextBlock FontSize="14"
         FontFamily="Comic Sans MS"
         Text="test" Foreground="Blue" />
   
  </Canvas>

 

and this is my Create object javascript code

 

function createSilverlight()
{
 var scene = new UntitledProject3.Page();
 Silverlight.createObjectEx({
  source: "Page.xaml",
  parentElement: document.getElementById("SilverlightControlHost"),
  id: "SilverlightControl",
  properties: {
   width: "100",
   height: "50",
   version: "1.0",
IsWindowless: "True",
background : "#00FFFFFF"
  },
  events: {
   onLoad: Silverlight.createDelegate(scene, scene.handleLoad)
  }
 });
}

y_makram
y_makram

Contributor

Contributor

6172 points

1,233 Posts

Re: Transparent Background

I have tried it on my machine right now, and it is working. Can you clear your browser cache, sometimes the browser just loads the XAML file form the cache and you may be seeing an old version. 

Thanks
Yasser Makram
http://www.silverlightrecipes.com
_____
Dont forget to click "Mark as Answer" on the post that helped you. If your question has not been answered, please post a followup question.

evilcoathanger
evilcoat...

Member

Member

10 points

5 Posts

Re: Transparent Background

I tried this same code as above.. and I am having the same issue. I also read your other thread but found the issue. Any ideas?

Heres the current code I'm using:

Default.html.js

function createSilverlight()
{
 var scene = new TestGradient.Page();
 Silverlight.createObjectEx({
  source: "Page.xaml",
  parentElement: document.getElementById("SilverlightControlHost"),
  id: "SilverlightControl",
  properties: {
   width: "100%",
   height: "100%",
   version: "1.0",
   IsWindowless: "True",
   background: "#00FFFFFF"
  },
  events: {
   onLoad: Silverlight.createDelegate(scene, scene.handleLoad)
  }
 });
}

 

Page.xaml

<Canvas
 xmlns="http://schemas.microsoft.com/client/2007"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 Width="640" Height="480"
 x:Name="Page"
 Background="Transparent"
 >
 <Rectangle Width="107" Height="107" Fill="#FFFFFFFF" Stroke="#FF000000" Canvas.Left="281" Canvas.Top="188" RadiusX="31.5" RadiusY="31.5"/>
</Canvas>

 Default.html CSS

 <style type="text/css">
  body {
   background-color: #ff0000;
  }
  .silverlightHost {
   height: 480px;
   width: 640px;
  }
 </style>

 

Thanks in advance.

evilcoathanger
evilcoat...

Member

Member

10 points

5 Posts

Re: Transparent Background

I figured out what the issue was:

Since this is javascript, it's very case sensitive obviously. In the code above, the property is stated as follows:

IsWindowless: "True",

When the correct statement is:

isWindowless: "True",

The I has to be lowercase to work.

Hopefully this fixes some peoples issues.

rakkanson
rakkanson

Member

Member

8 points

4 Posts

Re: Transparent Background

I also had the same issue.

 Ray Akkanson

GearWorld
GearWorld

Participant

Participant

846 points

1,105 Posts

Re: Transparent Background

For me, this

isWindowLess: "True",

background : "#00FFFFFF"

 

Gives me a Black background

 

evilcoathanger
evilcoat...

Member

Member

10 points

5 Posts

Re: Transparent Background

Here is how it breaks down the Background Color in Silverlight...

Think of it as 2 Seperate Letter/Number combinations put together..

Example: #00FFFFFF

The Bold "00" Means that the Alpha is 0%, and "FF" is 100% Alpha.

The Underline "FFFFFF" is your standard HTML Hex Code.

So, if you wanted a Red Background, the code would be "#FFFF0000"

Alpha "FF" , Hex Color "FF0000".

Hope this helps.

MarkRiemann
MarkRiemann

Member

Member

97 points

62 Posts

Re: Transparent Background

GearWorld,

 Is the capital L in isWindowLess right? I think it is suppose to be isWindowless without the capital L.

Thanks,

Mark.

 

evilcoathanger
evilcoat...

Member

Member

10 points

5 Posts

Re: Transparent Background

Good Catch Mark, that is true. The correct syntax is isWindowless as in my example above.

balukr54
balukr54

Member

Member

124 points

143 Posts

Re: Transparent Background

Hi all,

how can i clear the canvas backgroung color dynamically..

i code is given below.in one click canvas gets a color(working fine).. but not able to clear it. 

private void ButtonClear_Click(object sender, RoutedEventArgs e)

{

 rb1.IsEnabled = true;

 rb2.IsEnabled = true;

can.Background.ClearValue(Canvas.BackgroundProperty);

}

 private void ButtonSet_Click(object sender, RoutedEventArgs e)

 {

SolidColorBrush _buttonFillStyleNotApplied = new SolidColorBrush(Color.FromArgb(255, 34, 23, 67));

 rb1.IsEnabled = false;

rb2.IsEnabled = false;

can.Background = _buttonFillStyleNotApplied;

}

thanks

Balu

GearWorld
GearWorld

Participant

Participant

846 points

1,105 Posts

Re: Transparent Background

balukr54:

Hi all,

how can i clear the canvas backgroung color dynamically..

i code is given below.in one click canvas gets a color(working fine).. but not able to clear it. 

private void ButtonClear_Click(object sender, RoutedEventArgs e)

{

 rb1.IsEnabled = true;

 rb2.IsEnabled = true;

can.Background.ClearValue(Canvas.BackgroundProperty);

}

 private void ButtonSet_Click(object sender, RoutedEventArgs e)

 {

SolidColorBrush _buttonFillStyleNotApplied = new SolidColorBrush(Color.FromArgb(255, 34, 23, 67));

 rb1.IsEnabled = false;

rb2.IsEnabled = false;

can.Background = _buttonFillStyleNotApplied;

}

thanks

Balu

did you try : 

can.Background = new SolidColorBrush(Colors.Transparent);

ClosDesign
ClosDesign

Member

Member

8 points

11 Posts

Re: Transparent Background

 Is there a live working example of this someplace?????????

GearWorld
GearWorld

Participant

Participant

846 points

1,105 Posts

Re: Transparent Background

 

ClosDesign:

 Is there a live working example of this someplace?????????

 

Hi,

Just click on your SilverLight control on the asp.net page.  There's a ton of properties and one is Windowless.  Set it to true.
Then just make the LayoutRoot background of your page alpha channel 0.

Bingo !

 

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities