首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在你的地铁应用程序中自定义侧边栏滑动?

如何在你的地铁应用程序中自定义侧边栏滑动?
EN

Stack Overflow用户
提问于 2012-12-10 13:03:12
回答 4查看 2.8K关注 0票数 2

我正在开发一个地铁应用程序在那里,我想有一个自定义的条形幻灯片时,用户点击屏幕上的东西。

这就是我所说的:

代码语言:javascript
运行
复制
 --------------
|          |   |
|          |   |  <----
|          |   |
 ---------------
main screen  side
              bar

在这个侧边栏,我想有一些简单的控制,如图像和文本块等。

1)我该怎么做,如果有任何帮助,我将不胜感激

2)这并不违反metro原则,对吧?

EN

回答 4

Stack Overflow用户

发布于 2012-12-10 13:19:52

您可以尝试利用弹出按钮,如设置弹出按钮。你可能想看看Callisto

否则,您可以包含一个Xaml元素,该元素位于所有其他元素之上,并在屏幕上切换其可见性和位置。如何定位取决于您使用的根元素。为了在画布中定位元素,将Canvas.Right="0"添加到子元素中。

票数 4
EN

Stack Overflow用户

发布于 2012-12-10 13:18:47

您可以使用PopUp

看一下这个例子,

http://code.msdn.microsoft.com/windowsapps/App-settings-sample-1f762f49

票数 0
EN

Stack Overflow用户

发布于 2012-12-10 13:23:38

你可以使用下面的helper

WinRT Flyout Helper

代码语言:javascript
运行
复制
public class FlyoutHelper
{
    protected Popup m_Popup = new Popup();
    public Popup Show(Popup popup, FrameworkElement button, double offset = 35d)
    {
        if (popup == null)
            throw new Exception("Popup is not defined");
        m_Popup = popup;
        if (button == null)
            throw new Exception("Button is not defined");
        if (double.IsNaN(offset))
            throw new Exception("Offset is not defined");
        var _Child = popup.Child as FrameworkElement;
        if (_Child == null)
            throw new Exception("Popup.Child is not defined");
        if (double.IsNaN(_Child.Height))
            throw new Exception("Popup.Child.Height is not defined");
        if (double.IsNaN(_Child.Width))
            throw new Exception("Popup.Child.Width is not defined");

        // get position of the button
        var _Page = Window.Current.Content as Page;
        var _Visual = button.TransformToVisual(_Page);
        var _Point = _Visual.TransformPoint(new Point(0, 0));
        var _Button = new
        {
            Top = _Point.Y,
            Left = _Point.X,
            Width = button.ActualWidth,
            Height = button.ActualHeight,
        };

        // determine location
        var _TargetTop = (_Button.Top + (_Button.Height / 2)) - 
                         _Child.Height - offset;
        var _TargetLeft = (_Button.Left + (_Button.Width / 2)) - 
                          (_Child.Width / 2);

        if ((_TargetLeft + _Child.Width) > Window.Current.Bounds.Width)
            _TargetLeft = Window.Current.Bounds.Width - _Child.Width - offset;
        if (_TargetLeft < 0)
            _TargetLeft = offset;

        // setup popup
        popup.VerticalOffset = _TargetTop;
        popup.HorizontalOffset = _TargetLeft;

        // add pretty animation(s)
        popup.ChildTransitions = new TransitionCollection 
        { 
            new EntranceThemeTransition 
            { 
                FromHorizontalOffset = 0, 
                FromVerticalOffset = 20 
            }
        };

        // setup
        m_Popup.IsLightDismissEnabled = true;
        m_Popup.IsOpen = true;

        // handle when it closes
        m_Popup.Closed -= popup_Closed;
        m_Popup.Closed += popup_Closed;

        // handle making it close
        Window.Current.Activated -= Current_Activated;
        Window.Current.Activated += Current_Activated;

        // return
        return m_Popup;
    }

    protected void Current_Activated(object sender, WindowActivatedEventArgs e)
    {
        if (m_Popup == null)
            return;
        if (e.WindowActivationState == CoreWindowActivationState.Deactivated)
            m_Popup.IsOpen = false;
    }

    protected void popup_Closed(object sender, object e)
    {
        Window.Current.Activated -= Current_Activated;
        if (m_Popup == null)
            return;
        m_Popup.IsOpen = false;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13795260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档