开发者

how to set ScrollViewer's scroller at certain point in wp7?

I have a large canvas. In the casvas I'm adding textblock in code behind on drage event. Each time I add a textblock the Scrollviewer set/shows the first textbloc. Thus I have to manually scroll up to last text block. So I want to problematically set the Scrollviewer at last element of the canvas after a new textblock added. XAML:-

  <ScrollViewer x:Name="sv" HorizontalScrollBarVisibility="Auto" Margin="6,6,-835,66"> 
            <Canvas x:Name="canvas" Height="450" Width="12000" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"> 
            </Canvas> 
        </ScrollViewer> 

Code behind C#:-

     private void OnDragDelta(object sender, DragDeltaGestureEventArgs e) 
    { 

        if (tb_conter > 24) 
            return; 

        TextBlock[] tb = new TextBlock[elemet]; 
        for (int i = 0; i < elemet; i++) 
            tb[i] = new TextBlock(); 


        currentPoint = e.GetPosition(this.ContentPanel); 

        double x = currentPoint.X - oldPoint.X; 

        if (x >= 100) 
        { 

            tb[tb_conter].SetValue(Canvas.LeftProperty, t开发者_运维问答b_canvasLeft); 
            tb[tb_conter].SetValue(Canvas.TopProperty, tb_canvasTop); 

            tb[tb_conter].Text = time_scale.ToString(); 
            canvas.Children.Add(tb[tb_conter]); 

            time_scale++; 
            tb_conter++; 
            tb_canvasLeft += tb_canvasTop; 

        } 
        else 
            Debug.WriteLine(x.ToString()); 
    } 


You want the ScrollViewer.ScrollToVerticalOffset method.

Better still would be adding items to an ObservableCollection<string> in a view model and binding that to a ListBox on the page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜