设置Silverlight页面大小随web page大小变化的方法
Canvas 是绝对定位的,应改为 Grid ,而且 <Image Height="209" Width="83"/> 这个也不应当指定固定的 Height 和 Width
完整的xml代码如下所示:
<UserControl x:Class="AppSilverlightCwf.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" mc:Ignorable="d" Loaded="UserControl_Loaded" DataContext="{Binding}"> <Grid x:Name="CanvasRoot" Background="White"> <Image Name="image1" Stretch="Fill"> </Image> </Grid> </UserControl>
初始化函数如下所示:
public MainPage() { InitializeComponent(); // try { this.ScreenHeight = (int)Application.Current.Host.Content.ActualHeight; this.ScreenWidth = (int)Application.Current.Host.Content.ActualWidth; // this.ScreenWidth = (int)(this.ScreenWidth*1.0); this.ScreenHeight = (int)(this.ScreenHeight * 1.0); // this.viewDX = this.ScreenWidth / 2; this.viewDY = this.ScreenHeight / 2; // CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering); _graphics2D = new Graphics2D(ScreenWidth,(int)(ScreenHeight*1.0)); AffineTransform at = new AffineTransform();// new AffineTransform(1,-1,0); _graphics2D.AffineTransform = at; // _bmp = new WriteableBitmap(ScreenWidth,ScreenHeight); this.image1.source = _bmp; //DrawStringtest(); //this.Lines(); //this.initWorkflow(SLApp.rt_pid); RefreshBitmap(); } catch (Exception ee) { } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。