代码之家  ›  专栏  ›  技术社区  ›  Bharathi

xamarin forms android中使用带有字体属性的法语区域性时发生目标调用异常

  •  0
  • Bharathi  · 技术社区  · 7 年前

    我用了我的Xamarin页面上的标签 字体属性 如下我的xaml页面中的代码所示。默认情况下(美国文化)没有问题。当我将我的android设备文化更改为法语时,我得到的是system.reflection.targetInvocationException。如果我删除fonttattributes,它可以正常工作。我无法调试或从输出窗口获取详细信息。请大家帮忙。

    我的密码

    <Label x:Name="continentLabel" FontAttributes="Bold"/>
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   AbbyWang - MSFT    7 年前

    我创建了一个简单的Xamarin表单项目并编辑了您发布的Xaml文件,还添加了两个resx文件:appresources.resx和appresources.fr.resx,然后将模拟器的语言设置设置为法语。一切正常。我想你可能漏掉了什么,所以我把代码贴在这里:

    主页.xaml:

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:local="clr-namespace:App34"
                 x:Class="App34.MainPage">
    
        <StackLayout>
            <!-- Place new controls here -->
            <Label Text="Welcome to Xamarin.Forms!" 
               HorizontalOptions="Center"
               VerticalOptions="CenterAndExpand" />
            <Label x:Name="String1" 
               FontAttributes="Bold" 
               HorizontalOptions="Center"
               VerticalOptions="CenterAndExpand" />
        </StackLayout>
    
    </ContentPage>
    

    主页.xaml.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Xamarin.Forms;
    
    namespace App34
    {
        public partial class MainPage : ContentPage
        {
            public MainPage()
            {
                InitializeComponent();
                String1.Text = AppResources.String1;
    
            }
        }
    }
    
    推荐文章