代码之家  ›  专栏  ›  技术社区  ›  CXL

UWP XAML BladeView控件-将新创建的BladeItem滚动到视图中

  •  2
  • CXL  · 技术社区  · 8 年前

    我用的是 BladeView BladeMode 属性更改为 Fullscreen .

    当在我的代码中创建新的刀片时,我希望 布雷德维 似乎 就像我应该可以利用 StartBringIntoView() 为了完成这个,但它什么也没做。

    if (bladeView.BladeMode == BladeMode.Fullscreen)
    {
        // current window width
        Rect windowBounds = Window.Current.Bounds;
        int currentWidth = (int)windowBounds.Width;
    
        // scroll to view
        BringIntoViewOptions opts = new BringIntoViewOptions();
        Rect target = new Rect { Height = windowBounds.Height, Width = windowBounds.Width, X = currentWidth, Y = 0 };
        opts.TargetRect = target;
        newBlade.StartBringIntoView(opts);
    }
    

    这就是我的XAML树的样子:

    enter image description here

    1 回复  |  直到 8 年前
        1
  •  2
  •   CXL    8 年前

    我只是需要用 bladeView.UpdateLayout() 打电话之前 StartBringIntoView() .

    if (bladeView.BladeMode == BladeMode.Fullscreen)
    {
        // update the layout so StartBringIntoView() works
        bladeView.UpdateLayout();
    
        // scroll BladeView to newly-created BladeItem
        newBlade.StartBringIntoView();
    }