简体   繁体   English

Xamarin.Forms ToolBarItems问题与图像和文本

[英]Xamarin.Forms ToolBarItems issue with image and text

I have created a cross platform application in xamarin forms.In this I am using the Content Page.In the Content Page Navigation Bar i have added button using ToolBarItems.It is showing fine for Android and iOS but for UWP it is coming with the ellipsis.And when I click on ellipsis then only the button text are visible.Before clicking it seems like there is no button in the Navigation Bar. 我已经创建了一个xamarin形式的跨平台应用程序。在此我使用的是内容页面。在内容页面导航栏中,我使用ToolBarItems添加了按钮。它在Android和iOS上都很好用,但对于UWP来说是省略号当我单击省略号时,只有按钮文本可见。在单击之前,导航栏中似乎没有按钮。 Here Is the Screenshot of the Navigation bar before clicking the ellipsis. 这是单击省略号之前导航栏的屏幕截图。 在此处输入图片说明

Here is the screenshot of the navigation bar after the ellipsis is clicked. 这是单击省略号后导航栏的屏幕截图。 在此处输入图片说明

Is there any way to Open the ellipsis automatically without clicking on it for UWP. 有什么方法可以自动打开省略号,而无需单击以打开UWP。 Please help. 请帮忙。

Add Order="Primary" in ToolbarItem 在ToolbarItem中添加Order =“ Primary”

See UWB Section in Xamarin Forms Toolbar for more details 有关更多详细信息,请参见Xamarin表单工具栏中的 UWB部分。

<ContentPage.ToolbarItems> <ToolbarItem Order="Primary" Text="Sync" Icon="ic_sch_sync.png" Clicked="sync_clicked" x:Name="SyncItem" > </ToolbarItem> </ContentPage.ToolbarItems>

There is one more requirement I also had the same problem But what I found is that if the page Title is not set then the nav bar is not shown. 还有一个要求,我也有同样的问题,但是我发现,如果未设置“标题”页面,则不会显示导航栏。 So please set title in content page constructor. 因此,请在内容页面构造函数中设置标题。

By default the CommandBar in UWP has this natural behavior so you need to override the IsOpen Property of the CommandBar to show the text by default. 默认情况下,UWP中的CommandBar具有这种自然行为,因此默认情况下您需要覆盖CommandBarIsOpen属性以显示文本。

So you can create a Custom Renderer for and set its IsOpen property to true. 因此,您可以为其创建一个自定义渲染器并将其IsOpen属性设置为true。

Method 1 : 方法1:

Ok from the documentation I found that both the NavigationPage and ContentPage are Custom Framework elements on UWP. 文档中确定,我发现NavigationPageContentPage都是UWP上的Custom Framework元素。 So you can either debug to see how to Custom Framework incorporates the CommandBar and set its IsOpen property. 因此,您可以进行调试,以了解如何自定义框架合并CommandBar并设置其IsOpen属性。

Method 2 : 方法2:

Alternatively if you're looking for something simple you can just change the default behavior of all the CommandBar styles in your UWP app by adding this style resource in your App.xaml in UWP. 或者,如果您正在寻找简单的东西,只需在UWP中的App.xaml中添加样式资源,即可更改UWP应用中所有CommandBar样式的默认行为。 I've made the changes to this style with the IsOpen property set to true. 我已经将IsOpen属性设置为true来对此样式进行了更改。

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

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