silverlight应用程序只显示一部分的解决方案(路过的朋友留下脚印)

       前段时间,我自己也被silverlight应用程序在网页只显示一部分的问题困扰着!话了几天的时间在网上搜索资料、专著中找答案也没有找到答案。不过我写的那个页面在我的机子上是只显示一部,把那个页面考到别的机子上却又能完全显示。

      所以我认定是我的机子出了问题。不过通过我对silverlight的研究发现,silverlight应用程序,它的页面是受网页的影响的(它需要用浏览器来承接应用程序),所以网页的大小直接影响着silverlight应用程序的显示范围。

     因此,我们需要把应用程序的大小告诉浏览器,这样的话我们的问题就解决了。

示例:<UserControl x:Class="My.WelcomePage"
    xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml"
    Width="1000" Height="700">
    <Grid x:Name="LayoutRoot"  Width="1000" >
        <Grid.RowDefinitions>
            <RowDefinition Height="150"/>
            <RowDefinition Height="720"/>
            <RowDefinition Height="150"/>
        </Grid.RowDefinitions>
        <Grid.Background>
            <ImageBrush ImageSource="images/Welcome/DiTuOne.jpg"/>
        </Grid.Background>
        <Grid Grid.Row="0">
            <Canvas Canvas.Left="75" Canvas.Top="10" Height="120" Width="443">
                <Image Source="images/Welcome/logo.jpg">     
                </Image>
            </Canvas>
        </Grid>
        <Grid Grid.Row="1">
           
        </Grid>
        <Grid Grid.Row="2">
           
        </Grid>
    </Grid>
</UserControl>

 

就这样一个页面运行时,只能看到宽度为1000的,高度最多是150的范围的局部界面。

不过我把xaml页面的大小告诉,网页后,效果就完全不一样了。即给它加上一个LayoutRoot_LayoutUpdated事件用于通知浏览器。

<UserControl x:Class="My.WelcomePage"
    xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml"
    Width="1000" Height="700">
    <Grid x:Name="LayoutRoot"  Width="1000" LayoutUpdated="LayoutRoot_LayoutUpdated">
        <Grid.RowDefinitions>
            <RowDefinition Height="150"/>
            <RowDefinition Height="720"/>
            <RowDefinition Height="150"/>
        </Grid.RowDefinitions>
        <Grid.Background>
            <ImageBrush ImageSource="images/Welcome/DiTuOne.jpg"/>
        </Grid.Background>
        <Grid Grid.Row="0">
            <Canvas Canvas.Left="75" Canvas.Top="10" Height="120" Width="443">
                <Image Source="images/Welcome/logo.jpg">     
                </Image>
            </Canvas>
        </Grid>
        <Grid Grid.Row="1">
           
        </Grid>
        <Grid Grid.Row="2">
           
        </Grid>
    </Grid>
</UserControl>

 

并且在CS文件的该事件中添加上相应语句即可。

private void LayoutRoot_LayoutUpdated(object sender, EventArgs e)
        {

            Size size = this.LayoutRoot.DesiredSize;

 

            String heightInPixel = String.Format("{0}px", size.Height);

            String containerElementId = "silverlightControlHost";

            HtmlElement element = HtmlPage.Document.GetElementById(containerElementId);

            element.SetStyleAttribute("height", heightInPixel);

 

        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值