在silverlight版块三天无人回复
grid内含ScrollViewer,ScrollViewer内含canvas,窗体大小800*600,但是CANVAS里绘出来的图超过600高度,造成部分内容被截断没显示出来,现在我把Canvas拉高到1500,然后把Canvas的绘制起点从高度/2也就是750开始绘制,暂时可以显示完全,问题:因为是从750开始绘制 所以页面出来的时候,上面大概有四五百的地方是空的,需要手动拉动滚动条去下面才能看到图 我用sv.ScrollToVerticalOffset(750)想实现页面在展现出来的时候 自动滚动到750的位置,目前失败,求思路或代码,谢以下是代码:<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="Dtsc.WorkFlow.FlowInfo.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/up-compatibility/2006"
mc:Ignorable="d"
xmlns:my="clr-namespace:Dtsc.WorkFlow.Silverlight.Controls;assembly=Dtsc.WorkFlow.Silverlight.Controls"
d:DesignHeight="600" d:DesignWidth="800">
<Grid x:Name="grid1">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Height="20" HorizontalAlignment="Left" Margin="1,1,0,0" Name="ImgLegend" Stretch="Fill" VerticalAlignment="Top" Width="373" Source="Image/图例.png" Grid.RowSpan="2" />
<ScrollViewer VerticalScrollBarVisibility="Auto" Width="800" Height="600" Margin="0" HorizontalScrollBarVisibility="Auto" x:Name="sv" Grid.Row="1">
<Canvas Name="canva" Height="1500" />
</ScrollViewer>
</Grid>
</UserControl>
ublic MainPage(string rid, string vid, string showRule)
{
InitializeComponent();
RecordId = rid;
VersionId = vid;
ShowRule = showRule; client.GetRecordModelCompleted += new EventHandler<WorkFlowWebService.GetRecordModelCompletedEventArgs>(client_GetRecordModelCompleted);
client.GetRecordModelAsync(RecordId); ShowWhat(showRule);//包含在ScrollViewer中的Canvas上绘图
sv.ScrollToVerticalOffset(750);//滚动到750
}
<Grid Grid.Row="1" x:Name="grid1">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Height="20" HorizontalAlignment="Left" Margin="1,1,0,0" Name="ImgLegend" Stretch="Fill" VerticalAlignment="Top" Width="373" Source="Image/图例.png" Grid.RowSpan="2" />
<Canvas Name="canva" Grid.Row="1" SizeChanged="canva_SizeChanged">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" x:Name="sv">
<Rectangle Width="4000" Height="4000" />
</ScrollViewer>
</Canvas>
</Grid>
后台对应事件处理函数 private void canva_SizeChanged(object sender, SizeChangedEventArgs e)
{
sv.Width = e.NewSize.Width;
sv.Height = e.NewSize.Height;
}
public Window1()
{
InitializeComponent();
scrollViewer1.ScrollToVerticalOffset(70);
}
<Grid x:Name="LayoutRoot" Background="White">
<ScrollViewer Height="100" HorizontalAlignment="Left" Margin="10,10,0,0" Name="scrollViewer1" VerticalAlignment="Top" Width="200">
<StackPanel Height="200" Width="300" Background="Green">
<TextBlock Text="hello"></TextBlock>
<TextBlock Text="hello"></TextBlock>
<TextBlock Text="hellohellohellohellohellohellohellohellohello"></TextBlock>
<TextBlock Text="hello"></TextBlock>
<TextBlock Text="hello"></TextBlock>
<TextBlock Text="hello"></TextBlock>
</StackPanel>
</ScrollViewer>
</Grid>