我有一个Silverlight网站,我已经配置为使用一些JavaScript代码和Canvas控制ScaleTransform属性处理不同的分辨率。这很好,但是,只有当浏览器缩放设置为100%或更低时,才能最好地查看该网站。当我增加缩放级别时,浏览器不会提供任何滚动条,我的内容会被剪裁。我尝试了几个选项,比如使用CSS在正文中设置min-height
,但这没有用。 (请注意,我只需要在IE上测试网站)
这是我的缩放代码:
<navigation:Page x:Class="Mynamespace.Homepage"
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:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
Title="Home"
HorizontalAlignment="Stretch"
mc:Ignorable="d">
<Canvas x:Name="RootCanvas">
<Canvas.RenderTransform>
<ScaleTransform x:Name="PageScale"
ScaleX="1"
ScaleY="1" />
</Canvas.RenderTransform>
<Grid x:Name="RootGrid"
Canvas.Left="50"
Canvas.Top="5">
<Grid.RowDefinitions>
<RowDefinition Height="62" />
<RowDefinition Height="428*" />
</Grid.RowDefinitions>
<!-- First Grid Row contains Navigation menu -->
<!-- Second one contains a scrollviewer that holds a navigation frame -->
<Grid x:Name="ScrollGrid"
Grid.Row="1"
Width="700" />
<ScrollViewer x:Name="ScrollViewer1"
Grid.Row="1"
Margin="0,0,0,0"
Padding="0, 0, 0, 0"
VerticalScrollBarVisibility="Auto">
<sdk:Frame Name="MainFrame"
Width="Auto"
Height="Auto"
Margin="0,0,0,0"
Padding="0,0,0,0">
<sdk:Frame.UriMapper>
<sdk:UriMapper>
<!-- some uri mapping here -->
</sdk:UriMapper>
</sdk:Frame.UriMapper>
</sdk:Frame>
</ScrollViewer>
</Grid>
</Canvas>
以下是该页面背后的代码:
public Homepage()
{
InitializeComponent();
App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
App.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
HtmlPage.RegisterScriptableObject("Homepage", this);
if (App.Current.Host.IsLoaded)
{
HtmlPage.Window.Invoke("ResizeSLContainer");
}
}
[ScriptableMember]
public void ScaleContainer(double containerHeight, double containerWidth)
{
if (containerHeight != 0 && containerWidth != 0)
{
ScaleTransform scale = this.FindName("PageScale") as ScaleTransform;
scale.ScaleX = containerHeight / 744;
scale.ScaleY = containerHeight / 744;
}
}
void Content_FullScreenChanged(object sender, EventArgs e)
{
if (App.Current.Host.IsLoaded)
{
HtmlPage.Window.Invoke("ResizeSLContainer");
}
}
void Content_Resized(object sender, EventArgs e)
{
if (App.Current.Host.IsLoaded)
{
HtmlPage.Window.Invoke("ResizeSLContainer");
}
}
最后是js:
function ResizeSLContainer() {
var slPlugin = document.getElementById("SilverlightControl");
//Scale Canvas
slPlugin.Content.Homepage.ScaleContainer(slPlugin.content.actualHeight, slPlugin.content.actualWidth);
//Resize main Container
if (slPlugin.content.actualHeight > 0) {
slPlugin.width = (slPlugin.content.actualHeight / 744) * 1005;
}
}
答案 0 :(得分:0)
您可以通过将处理程序附加到Content.Zoomed事件来响应托管代码中的缩放事件,如下所示:
Application.Current.Host.Content.Zoomed += new EventHandler(this.ContentZoomed);
使用zoom design或adaptive UI修复布局。