在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
 }

解决方案 »

  1.   

    xaml部分代码,其中Rectangle 只是为了测试而添加的,模拟里面有个大图:
            <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;
            }
      

  2.   

    我测了下ScrollToVerticalOffset()能用啊,楼主你肯定是什么地方写错了。
            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>
      

  3.   

    调试的时候突然发现在UserControl的Loaded事件里canva的Children是0,于是果断把sv..ScrollToVerticalOffset放到canva.loaded事件里 已经能滚动,可是,1500的高度 我让滚动到750,它是滚动条的顶端离顶部750,而不是滚动条的中间离顶部750,还是没达到要求 我正在调试
      

  4.   

    qldsrx兄的建议我参考下调试下吧,canvas里有比较复杂的计算,我试试