Silverlight處女在這裏。如何使圍繞我的網格的用戶控件自動調整大小以適應網格寬度?目前,當瀏覽器窗口更寬時,usercontrol顯示的像素大約爲300或400像素。它在醜陋的數據網格周圍呈現垂直和水平滾動條。我想將控件寬度設置爲「100%」,但這似乎不受支持。我錯過了什麼?自動寬度和高度的Silverlight網格
這裏是我的XAML至今:
<UserControl x:Class="RichMedia.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">
<Grid x:Name="LayoutRoot" Background="White">
<data:DataGrid Name="dataGrid1" AutoGenerateColumns="False"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
DataContext="{Binding}" />
</Grid>
</UserControl>
編輯:我要補充一點,我使用的是默認容器在Visual Studio 2010中創建添加Silverlight應用程序到現有的Web應用程序項目時。
下面是從託管頁面的標記:
<%@ Page Language="C#" AutoEventWireup="true" %>
<!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" >
<head runat="server">
...
<style type="text/css">
html, body { height: 100%; overflow: hidden; }
body { padding: 0; margin: 0; }
html, body { height: 100%; overflow: hidden; }
#silverlightControlHost { height: 100%; text-align:center; }
</style>
<script type="text/javascript" src="Scripts/Silverlight.js"></script>
...
</head>
<body>
<form id="form1" runat="server" style="height:100%">
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/RichMedia.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40818.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration:none"><img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/></a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>
</body>
</html>
感謝您的回覆。我編輯了這個問題,因爲我相信你所有的建議(我的UC寬度/高度)都已經被VS模板處理過了。但我仍然有一個顯示網格的小窗口。仍在撓我的腦海...... – grenade
原來,我的'HorizontalAlignment =「Stretch」VerticalAlignment =「Stretch」'導致了這個問題。當我從數據中取消這些屬性時:DataGrid元素網格佔用了所有可用空間。 – grenade