简体   繁体   English

AppBar WP8.1中的自定义控件

[英]Custom control inside AppBar WP8.1

the appbar in WP8.1 is not very flexible and we are limited to some kind of fixed controls like the appbarbutton, appbarseparator... But I want to add a stackpanel to the AppBar. WP8.1中的appbar不是很灵活,我们仅限于某种固定控件,如appbarbutton,appbarseparator ......但我想在AppBar中添加一个stackpanel。 AppbarButton and AppBarSeparator both are implementing "ICommandBarElement". AppbarButton和AppBarSeparator都在实现“ICommandBarElement”。 Easy I thought, lets create a custom control, inheriting from StackPanel and implementing the interface "ICommandBarElement" and done. 我想,我们可以创建一个自定义控件,继承自StackPanel并实现接口“ICommandBarElement”并完成。 But actually is not easy but impossible to make this work. 但实际上并不容易,但不可能使这项工作。 I tried inheriting from a Button and implementing that interface, to make an exact replica of an AppBarButton, but even this isn't working. 我尝试继承Button并实现该接口,以制作AppBarButton的精确副本,但即使这样也行不通。

 using Windows.Foundation;
using Windows.UI.Xaml.Controls;

internal class AppbarRectangle : Button, ICommandBarElement
{
    public AppbarRectangle()
    {
        Loaded += AppbarRectangle_Loaded;
    }

    private void AppbarRectangle_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
    {
    }

    protected override Size ArrangeOverride(Size finalSize)
    {
        return base.ArrangeOverride(finalSize);
    }

    protected override Size MeasureOverride(Size availableSize)
    {
        return base.MeasureOverride(availableSize);
    }

    protected override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
    }

    public bool IsCompact
    {
        get
        {
            return false;
        }
        set
        {
        }
    }
}

I don't have any clues of what I have to do to insert custom controls inside the AppBar because it's really limited. 我没有任何线索可以在AppBar中插入自定义控件,因为它确实有限。 Any ideas? 有任何想法吗?

Thanks. 谢谢。

The AppBar on Windows Phone is displayed as system UI, not as part of your app itself. Windows Phone上的AppBar显示为系统UI,而不是应用程序本身的一部分。 Only the items the system understands (essentially the icon masks and text from AppBarButtons and the Foreground and Background colours from the CommandBar) can be used. 只能使用系统理解的项目(基本上是AppBarButtons中的图标蒙版和文本以及CommandBar中的前景色和背景色)。 This is why you cannot use arbitrary controls or coloured icons on the phone like you can on Windows. 这就是为什么你不能像在Windows上那样使用手机上的任意控件或彩色图标。

If you want a more customized AppBar then you'll have to implement it yourself rather than using the in-box AppBar. 如果你想要一个更加个性化的AppBar,那么你必须自己实现它,而不是使用内置的AppBar。 So long as you follow the basic design concepts from the system AppBar it shouldn't confuse your users. 只要您遵循系统AppBar的基本设计概念,就不应该混淆您的用户。 You can take a look at what the Photos app and IE do as example extended designs. 您可以查看照片应用和IE作为示例扩展设计的内容。

This is not supported by Microsoft because they want a generic look and feel for the standard controls. Microsoft不支持此功能,因为它们需要标准控件的通用外观。 so in the app bar you can only add these basic items. 所以在应用栏中你只能添加这些基本项目。

the only solution you could think of is building your own app bar control although question would be if that is the solution your customers would want. 您可以想到的唯一解决方案是构建自己的应用栏控件,但问题是,如果这是您的客户想要的解决方案。 because they are used to the standard app bar. 因为它们习惯于标准应用栏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM