Feb 2 2009

How to center the Silveright application inside the ASPX page

Category: silverlight 2.0Bil@l @ 21:29

A very simple CSS trick to center the Silverlight application, check the following:

<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls"
    TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" style="height:100%;">
<head runat="server">
    <title>SilverlightDataGrid</title>
    <style type= "text/css">
        body { text-align: center; }
        div#container { margin-left: auto; margin-right: auto; width: 50em; }
    </style>

</head>
<body style="height:100%;margin:0;">
    <form id="form1" runat="server" style="height:100%;">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div id="container" style="height:100%;">
            <asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/SilverlightDataGrid.xap" MinimumVersion="2.0.31005.0" Width="100%" Height="100%" />
        </div>
    </form>
</body>
</html>

 Notice the bolded sections above. This is enough to center your application in the middle of the ASPX page.

 

Hope this helps,
Regards

Tags:

Comments are closed