始终在RTXAML中的flipview控件上显示导航箭头

时间:2013-10-04 09:10:27

标签: xaml windows-store-apps winrt-xaml

我正在为Windows 8商店应用程序使用XAML FlipView控件。

当我使用鼠标并且鼠标悬停在FlipView控件上时,会显示上一个/下一个导航按钮。

但是,如果我不使用鼠标并使用触摸,则会隐藏导航按钮。

我希望导航按钮始终可见。我怎么能这样做?

我查看了控件模板,但我看不到任何设置导航按钮可见性的内容。

TA

1 个答案:

答案 0 :(得分:2)

试试dynamically hide/show the buttons

private void Show(object sender, RoutedEventArgs e)
{
    ButtonShow(fv, "PreviousButtonHorizontal");
    ButtonShow(fv, "NextButtonHorizontal");
    ButtonShow(fv, "PreviousButtonVertical");
    ButtonShow(fv, "NextButtonVertical");
}
private void Hide(object sender, RoutedEventArgs e)
{
    ButtonHide(fv, "PreviousButtonHorizontal");
    ButtonHide(fv, "NextButtonHorizontal");
    ButtonHide(fv, "PreviousButtonVertical");
    ButtonHide(fv, "NextButtonVertical");
}
private void ButtonHide(FlipView f, string name)
{
    Button b;
    b = FindVisualChild<Button>(f, name);
    b.Opacity = 0.0;
    b.IsHitTestVisible = false;
}
private void ButtonShow(FlipView f, string name)
{
    Button b;
    b = FindVisualChild<Button>(f, name);
    b.Opacity = 1.0;
    b.IsHitTestVisible = true;
}
private childItemType FindVisualChild<childItemType>(DependencyObject obj, string name) where childItemType : FrameworkElement
{
    // Exec
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
    {
        DependencyObject child = VisualTreeHelper.GetChild(obj, i);
        if (child is childItemType && ((FrameworkElement)child).Name == name)
            return (childItemType)child;
        else
        {
            childItemType childOfChild = FindVisualChild<childItemType>(child, name);
            if (childOfChild != null)
                return childOfChild;
        }
    }
    return null;
}