Xaml 如何在metro应用程序中从右侧自定义侧栏幻灯片?

Xaml 如何在metro应用程序中从右侧自定义侧栏幻灯片?,xaml,windows-8,microsoft-metro,winrt-xaml,Xaml,Windows 8,Microsoft Metro,Winrt Xaml,我正在开发一个metro应用程序,当用户点击屏幕上的某个东西时,我希望有一个定制的酒吧幻灯片 这就是我所说的:- -------------- | | | | | | <---- | | | --------------- main screen side bar -------------- | | | || |您可以使用弹出窗口 看看这个例子 您可以使用弹出窗口

我正在开发一个metro应用程序,当用户点击屏幕上的某个东西时,我希望有一个定制的酒吧幻灯片

这就是我所说的:-

 --------------
|          |   |
|          |   |  <----
|          |   |
 ---------------
main screen  side
              bar
--------------
|          |   |

|| |您可以使用弹出窗口

看看这个例子


您可以使用弹出窗口

看看这个例子


您可以尝试利用像“设置”弹出按钮这样的弹出按钮。你可能想看看


否则,您可以包含一个Xaml元素,该元素比所有其他元素都重要,并在屏幕上切换其可见性和位置。如何定位取决于您使用的根元素。要在画布中定位元素,请向子元素添加
canvas.Right=“0”

您可以尝试使用类似“设置”弹出按钮的弹出按钮。你可能想看看


否则,您可以包含一个Xaml元素,该元素比所有其他元素都重要,并在屏幕上切换其可见性和位置。如何定位取决于您使用的根元素。要在画布中定位元素,请向子元素添加
canvas.Right=“0”

您可以使用以下帮助程序

公共类弹出式窗口帮助器
{
受保护的弹出菜单m_Popup=新弹出菜单();
公共弹出窗口显示(弹出窗口,FrameworkElement按钮,双偏移=35d)
{
如果(弹出==null)
抛出新异常(“未定义弹出窗口”);
m_Popup=弹出窗口;
如果(按钮==null)
抛出新异常(“未定义按钮”);
if(双精度IsNaN(偏移))
抛出新异常(“未定义偏移量”);
var\u Child=popup.Child作为框架元素;
if(_Child==null)
抛出新异常(“未定义Popup.Child”);
if(双IsNaN(_儿童身高))
抛出新异常(“Popup.Child.Height未定义”);
if(double.IsNaN(_Child.Width))
抛出新异常(“Popup.Child.Width未定义”);
//获取按钮的位置
var_Page=Window.Current.Content作为页面;
var _Visual=button.TransformToVisual(_页面);
var_Point=_Visual.TransformPoint(新点(0,0));
var _按钮=新建
{
Top=_Point.Y,
左=_点.X,
宽度=按钮实际宽度,
高度=按钮实际高度,
};
//确定位置
var _TargetTop=(_Button.Top+(_Button.Height/2))-
_高度偏移;
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-偏移量;
如果(_TargetLeft<0)
_TargetLeft=偏移量;
//设置弹出窗口
popup.VerticalOffset=\u TargetTop;
popup.HorizontalOffset=_TargetLeft;
//添加漂亮的动画
popup.ChildTransitions=新建TransitionCollection
{ 
新入口-超转换
{ 
FromHorizontalOffset=0,
FromVerticalOffset=20
}
};
//设置
m_Popup.IsLightDismissEnabled=true;
m_Popup.IsOpen=真;
//当它关闭时处理
m_Popup.Closed-=Popup_Closed;
m_Popup.Closed+=Popup_Closed;
//把手关上
Window.Current.Activated-=当前\激活;
Window.Current.Activated+=当前\激活;
//返回
返回m_弹出窗口;
}
已激活受保护的无效电流(对象发送器,WindowActivatedEventArgs e)
{
如果(m_Popup==null)
回来
如果(例如WindowActivationState==CoreWindowActivationState.Deactivated)
m_Popup.IsOpen=假;
}
受保护的无效弹出窗口关闭(对象发送方,对象e)
{
Window.Current.Activated-=当前\激活;
如果(m_Popup==null)
回来
m_Popup.IsOpen=假;
}
}

您可以使用以下帮助程序

公共类弹出式窗口帮助器
{
受保护的弹出菜单m_Popup=新弹出菜单();
公共弹出窗口显示(弹出窗口,FrameworkElement按钮,双偏移=35d)
{
如果(弹出==null)
抛出新异常(“未定义弹出窗口”);
m_Popup=弹出窗口;
如果(按钮==null)
抛出新异常(“未定义按钮”);
if(双精度IsNaN(偏移))
抛出新异常(“未定义偏移量”);
var\u Child=popup.Child作为框架元素;
if(_Child==null)
抛出新异常(“未定义Popup.Child”);
if(双IsNaN(_儿童身高))
抛出新异常(“Popup.Child.Height未定义”);
if(double.IsNaN(_Child.Width))
抛出新异常(“Popup.Child.Width未定义”);
//获取按钮的位置
var_Page=Window.Current.Content作为页面;
var _Visual=button.TransformToVisual(_页面);
var_Point=_Visual.TransformPoint(新点(0,0));
var _按钮=新建
{
Top=_Point.Y,
左=_点.X,
宽度=按钮实际宽度,
高度=按钮实际高度,
};
//确定位置
var _TargetTop=(_Button.Top+(_Button.Height/2))-
_高度偏移;
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-偏移量;
如果(_TargetLeft<0)
_TargetLeft=偏移量;
//设置弹出窗口
垂直弹出窗口
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;
    }
}