Custom Loading no Silverlight

By rdorta at setembro 30, 2009 11:12
Filed Under: Silverlight

Olá amigos, já repararam que toda aplicação em Silverlight sempre tem o mesmo Loading? Esse loading vem do próprio Silverlight e por já existir dificilmente nós desenvolvedores mudamos essa animação.

Mas para os intrépidos designers que não se conformam com isso (inclusive o que trabalha comigo) segue abaixo a forma como você pode trocar seu loading e ainda por cima como você pode manipular objetos via Javascript, muito necessário quando você está utilizando Silverlight em páginas que não são criadas com .Net (aspx).

Abaixo segue o código HTML do Silverlight:

<script type="text/javascript" src="Splash/SplashScreen.js"></script> 
...
...
<object id="Xaml1" data="data:application/x-silverlight-2," 
type="application/x-silverlight-2" width="100%" height="100%"> ...
<param name="splashscreensource" value="Splash/SplashScreen.xaml"/>
<param name="onSourceDownloadProgressChanged" value="onSourceDownloadProgressChanged" />
 

Agora em sua aplicação crie uma página SplashScreen.XAML:

<StackPanel xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
VerticalAlignment="Center" Margin="0,100,0,0">
<Image Source="../Splash/slc-watermark.png"
Height="47" Width="343"
HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="10" />
<Grid HorizontalAlignment="Center">
<Rectangle x:Name="rectBorder" StrokeThickness="1" Stroke="#FFC8C8C8"
Height="7" Width="200" HorizontalAlignment="Left"/>
<Rectangle x:Name="rectBar" Fill="#FFC8C8C8"
Height="7" Width="0" HorizontalAlignment="Left" />
</Grid>
</StackPanel>

 

E por fim, segue o código javascript para movimentar a barra de loading:

function onSourceDownloadProgressChanged(sender, eventArgs) {
var myHost = document.getElementById("Xaml1");
var rectBar = myHost.content.findName("rectBar");
var rectBorder = myHost.content.findName("rectBorder");
if(eventArgs.progress)
rectBar.Width = eventArgs.progress * rectBorder.Width;
else
rectBar.Width = eventArgs.get_progress() * rectBorder.Width;
}

 

Me perdoem amigos desenvolvedores por dar armas ao seus designers e fazer com que eles atormentem a vida de vocês, mas uma aplicação Silverlight bem feita envolve sempre um bom designer :)

Até a próxima Arqinovação!!!

Comentários

26/12/2009 21:02:46 #

havaianas

Thanks for the article. Blogging is replacing main stream news for many black people.

havaianas United Kingdom | Reply

27/3/2010 14:39:28 #

skin beauty

Good of you to mention this. It might happen to any of us in the future..

skin beauty United Kingdom | Reply

6/5/2010 15:33:50 #

Australian Luxe

I completely agree with the above comment, the internet is with a doubt growing into the most important medium of communication across the globe and its due to sites like this that ideas are spreading so quickly.

Australian Luxe United Kingdom | Reply

6/5/2010 18:41:29 #

Australian Luxe

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.

Australian Luxe United Kingdom | Reply

16/6/2010 17:59:06 #

cheap

Helpful story. It really sums up the benefits of fish oil and Omega-3

cheap United Kingdom | Reply

17/7/2010 5:23:24 #

Ways to Lose Weight Fast

Hey there, I just thought you'd like to know that your blog's layout is all messed up in K-Meleon (browser) for some reason. You might want to check out your HTML code. -Philip

Ways to Lose Weight Fast United States | Reply

Comentar




  Country flag

biuquote
  • Comentário
  • Pré-visualização
Loading



Sobre mim

Ricardo Dorta

Ricardo Dorta

Arquiteto de sistemas da Makesys, atua na área de desenvolvimento de aplicações .NET há 5 anos.
MCP, MCAD e MCSD.