Posts Tagged 'silverlight'

Right-align a TextBlock in Silverlight

There is currently no way to right-align a TextBlock UI Element in Silverlight, though you can use this workaround to properly position your TextBlock to make it appear right-aligned:


    <TextBlock Text="My Text" Loaded="TextBlock_Loaded" Width="80"/>

The Loaded event handler

       private void TextBlock_Loaded(object sender, RoutedEventArgs e)
            TextBlock tb = (TextBlock) sender;
            Canvas.SetLeft(tb, Canvas.GetLeft(tb) + tb.Width - tb.ActualWidth);

By wrapping the TextBlock in the Canvas container, you can fix its position easily.


Silverlight object-tag problems in Firefox

Silverlight apps are embedded into web pages using the <object> tag. Now for some reason, Firefox refuses to instantiate the Silverlight application if the object-tag attributes are not in a certain order. As example, this won’t work in Firefox:

<object width="100%" height="100%" 
data="data:application/x-silverlight-2" type="application/x-silverlight-2">

One has to position the data and  type attributes first to make it work, like this:

<object data="data:application/x-silverlight-2" type="application/x-silverlight-2" 
width="100%" height="100%">

Strange bug..