如何在Xamarin WPF中使用TabbedPage
我正在尝试使用Xamarin表单重建旧的WinForms应用程序,以提高可移植性 应用程序使用一个如何在Xamarin WPF中使用TabbedPage,wpf,xaml,xamarin,xamarin.forms,Wpf,Xaml,Xamarin,Xamarin.forms,我正在尝试使用Xamarin表单重建旧的WinForms应用程序,以提高可移植性 应用程序使用一个TabControl,并说最接近的Xamarin表单元素是TabbedPage 代码如下: <?xml version="1.0" encoding="utf-8" ?> <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns
TabControl
,并说最接近的Xamarin表单元素是TabbedPage
代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MyApp"
x:Class="MyApp.MainPage">
<TabbedPage.ToolbarItems>
<ToolbarItem Text="Settings"
Order="Primary"
Priority="0" />
<ToolbarItem Text="Tools"
Order="Primary"
Priority="1" />
<ToolbarItem Text="Help"
Order="Primary"
Priority="2" />
</TabbedPage.ToolbarItems>
<TabbedPage.Children>
<ContentPage Title="Main">
<Label Text="Coming soon!"/>
</ContentPage>
<ContentPage Title="Today">
<Label Text="Coming soon!"/>
</ContentPage>
<ContentPage Title="This week">
<Label Text="Coming soon!"/>
</ContentPage>
</TabbedPage.Children>
</TabbedPage>
它在我的UWP构建中运行良好:
但是,在我的WPF版本中,它没有显示工具栏,因此无法切换选项卡:
那么我做错了什么
谢谢
更新#1:我尝试构建GTK目标,它工作正常:
这张截图是在Ubuntu上拍摄的。Windows上的GTK工作原理相同,但控件的绘图太麻烦。在搞乱工具栏中的元素选择器后,我终于找到了答案: WPF中有用于在选项卡之间切换的按钮。然而,它们只是看不见的: 在
TabbedPage
中设置BarTextColor
属性可以解决以下问题:
因此产生的代码是:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:TimetableApp"
x:Class="TimetableApp.MainPage"
BarTextColor="Black">
<TabbedPage.ToolbarItems>
<ToolbarItem Text="Settings"
Order="Primary"
Priority="0" />
<ToolbarItem Text="Tools"
Order="Primary"
Priority="1" />
<ToolbarItem Text="Help"
Order="Primary"
Priority="2" />
</TabbedPage.ToolbarItems>
<TabbedPage.Children>
<ContentPage Title="Main">
<Label Text="Coming soon!"/>
</ContentPage>
<ContentPage Title="Today">
<Label Text="Coming soon!"/>
</ContentPage>
<ContentPage Title="This week">
<Label Text="Coming soon!"/>
</ContentPage>
</TabbedPage.Children>
</TabbedPage>
在搞乱工具栏中的元素选择器后,我终于找到了答案: WPF中有用于在选项卡之间切换的按钮。然而,它们只是看不见的: 在
TabbedPage
中设置BarTextColor
属性可以解决以下问题:
因此产生的代码是:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:TimetableApp"
x:Class="TimetableApp.MainPage"
BarTextColor="Black">
<TabbedPage.ToolbarItems>
<ToolbarItem Text="Settings"
Order="Primary"
Priority="0" />
<ToolbarItem Text="Tools"
Order="Primary"
Priority="1" />
<ToolbarItem Text="Help"
Order="Primary"
Priority="2" />
</TabbedPage.ToolbarItems>
<TabbedPage.Children>
<ContentPage Title="Main">
<Label Text="Coming soon!"/>
</ContentPage>
<ContentPage Title="Today">
<Label Text="Coming soon!"/>
</ContentPage>
<ContentPage Title="This week">
<Label Text="Coming soon!"/>
</ContentPage>
</TabbedPage.Children>
</TabbedPage>
我想比较表告诉您必须对WPF和WinForm使用TabControl。@是的。如果我在WinForms上编程,我必须使用TabControl。但是,我正在使用Xamarin表单输出一个类似WPF的应用程序,所以我必须使用TabbedPage。我想比较表告诉您必须对WPF和WinForm使用TabControl。@Shaw是的。如果我在WinForms上编程,我必须使用TabControl。然而,我使用Xamarin表单输出类似WPF的应用程序,所以我必须使用TabbedPage。