日期:2014-05-18  浏览次数:20795 次

求助:关于silverlight滚动条,在silverlight版块三天无人回复

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

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

------解决方案--------------------
我测了下ScrollToVerticalOffset()能用啊,楼主你肯定是什么地方写错了。
C# code
        public Window1()
        {