【问题标题】:Xamarin Forms NavigationPage.TitleView RTL, the content disapperedXamarin Forms NavigationPage.TitleView RTL,内容消失了
【发布时间】:2020-05-08 14:47:25
【问题描述】:

我有一个支持 RTL 的 xamarin.forms 应用程序,但是当我将页面转换为 RTL 时,NavigationPage.TitleView 文本消失了。

NavigationPage.TitleView 代码:

<NavigationPage.TitleView>
    <Label Text="{Binding Title}" Style="{StaticResource TittleLabel}" HorizontalTextAlignment="Start" HorizontalOptions="Start" VerticalOptions="CenterAndExpand"></Label>
</NavigationPage.TitleView>

这是Result screen

提前致谢。

【问题讨论】:

    标签: xamarin mobile xamarin.forms


    【解决方案1】:

    对于 RTL,标签有 RTL 问题。请在下面找到问题链接。

    https://github.com/xamarin/Xamarin.Forms/issues/3611

    将 RTL 设置为 Page 时,标题视图消失。您可以向 Xamarin 团队报告。对于不是通过Label设置标题,而是直接设置ContentPage的title属性,如下所示,

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:d="http://xamarin.com/schemas/2014/forms/design"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 mc:Ignorable="d"
                 Title="RTL"
                 FlowDirection="RightToLeft">
    

    它正在工作,但 RTL 不适用。但是会显示标题。您也可以报告此问题。

    【讨论】:

      【解决方案2】:

      我想也许绑定不起作用。我制作了一个样本供您参考。

      MainPage.xaml

      <StackLayout>
          <Button Clicked="Button_Clicked" Text="Title View Page" />
      </StackLayout>
      

      MainPage.xaml.cs

       private void Button_Clicked(object sender, EventArgs e)
          {
              Navigation.PushAsync(new TitleViewPage());
          }
      

      TitleViewPage.xaml

       <ContentPage.Resources>
          <ResourceDictionary>
              <Style x:Key="TittleLabel" TargetType="Label">
                  <Setter Property="TextColor" Value="Green" />
                  <Setter Property="FontSize" Value="Large" />
              </Style>
          </ResourceDictionary>
      </ContentPage.Resources>
      <NavigationPage.TitleView>
          <StackLayout>
              <Label
                  HorizontalOptions="Start"
                  HorizontalTextAlignment="Start"
                  Style="{StaticResource TittleLabel}"
                  Text="{Binding Title}"
                  VerticalOptions="CenterAndExpand" />
          </StackLayout>
      </NavigationPage.TitleView>
      <ContentPage.Content>
          <StackLayout>
              <Label
                  HorizontalOptions="CenterAndExpand"
                  Text="Welcome to TitleView Page!"
                  VerticalOptions="CenterAndExpand" />
          </StackLayout>
      </ContentPage.Content>
      

      TitleViewPage.xaml.cs

      公共字符串标题{获取;放; } 公共 TitleViewPage() { 初始化组件(); Title = "我的 TitleView"; this.BindingContext = this; }

      App.xaml.cs

      public App()
          {
              InitializeComponent();
      
              MainPage = new NavigationPage(new MainPage());
          }
      

      更新:

      当您将FlowDirection设置为RightToLeft时,可以在横屏上看到titleview。

      在从右到左的本地化文档中,它列出了限制。 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization/right-to-left

      NavigationPage 按钮位置、工具栏项位置和过渡动画由设备区域设置控制,而不是 FlowDirection 属性。

      这个问题也被报道了。你可以关注更新。 https://github.com/xamarin/Xamarin.Forms/issues/9083

      【讨论】:

      • 感谢 Wendy 的答案绑定运行良好,此问题仅在将页面方向更改为 RTL 时出现,但在 LTR 中运行良好
      • 我已经更新了回复。我希望这会有所帮助。
      【解决方案3】:

      这种方法对我有用:

      -为 ContentPage 的内容(而不是 ContentPage)的主布局(包装器)设置 RTL-FlowDirection

      App.xaml

      <Application.Resources>
        <ResourceDictionary>
      
           <Style x:Key="PageTitleStyle" TargetType="Label">
              <Setter Property="HorizontalOptions" Value="EndAndExpand"/>
              <Setter Property="Padding" Value="0,0,5,0"/>
           </Style>
      
        </ResourceDictionary>
      </Application.Resources>
      

      MainPage.xaml

      <ContentPage ....>
      
         <NavigationPage.TitleView >
              <Label Text="{Binding Title}"  Style="{StaticResource PageTitleStyle}"  />
          </NavigationPage.TitleView>
      
        <StackLayout FlowDirection="RightToLeft">
          ....
       </StackLayout> 
      
      </ContentPage>
      

      【讨论】:

        猜你喜欢
        • 2020-09-21
        • 1970-01-01
        • 2015-05-03
        • 1970-01-01
        • 2020-02-15
        • 1970-01-01
        • 2021-10-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多