Xamarin.ios - xaml文件中的resx引用不起作用

时间:2016-05-19 12:52:20

标签: ios xaml xamarin xamarin.ios resx

我有一个AppResources.resx文件,我存储了在我的应用中使用的所有字符串。我的Xamarin项目包含两个解决方案,一个用于Android,另一个用于iOS。 Android应用程序运行正常。但iOS应用程序正在抛出Xaml错误,例如“无法找到静态成员AppResources”。

这是我的xaml:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:HalliganTL;assembly=HalliganTL"
             x:Class="HalliganTL.View.LoginPage">
  <Grid Style="{StaticResource backgroundColor}">
    <Grid.RowDefinitions>
      <RowDefinition Height="4*" />
      <RowDefinition Height="*" />
      <RowDefinition Height="*" />
      <RowDefinition Height="2*" />
      <RowDefinition Height="*" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="20" />
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="20" />
    </Grid.ColumnDefinitions>


    <Entry x:Name="entryEmail"
           Placeholder="{x:Static local:AppResources.login_page_email_placeholder}" Text="{Binding Username}" Grid.Row="1" Grid.Column="1" />
    <Entry x:Name="entryPassword"
           Placeholder="{x:Static local:AppResources.login_page_password_placeholder}"
           Text="{Binding Password}" IsPassword="true" Grid.Row="2" Grid.Column="1"/>
    <ActivityIndicator x:Name="activityIndicator" IsRunning="False" Grid.Row="3" Grid.Column="1" />
    <Button Text="{x:Static local:AppResources.login_page_login_button_text}"
            Style="{StaticResource redButton}" Clicked="OnLoginButtonClicked" Grid.Row="4" Grid.Column="1"/>
    <Button Text="{x:Static local:AppResources.login_page_forgot_password_button_text}"
           Style="{StaticResource blueButton}" Clicked="OnForgotPasswordClicked" Grid.Row="5" Grid.Column="1"/>


  </Grid>
</ContentPage>

关于导致此错误的原因的任何提示?

更新

我删除了XAML文件中的所有AppResources.resx引用,然而它抛出一个错误,告诉我.cs代码中不存在“OnLoginButtonClicked”方法。但显然确实如此!

这是我的.cs代码:

using Newtonsoft.Json;
using HalliganTL.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using XLabs.Ioc;

namespace HalliganTL.View
{
    public partial class LoginPage : ContentPage
    {
        public LoginPage()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);
            Title = AppResources.login_page_title;
            BindingContext = new MainViewModel();
        }

        async void OnForgotPasswordClicked(object sender, EventArgs e)
        {
            await Navigation.PushAsync(new ForgotPasswordPage());
        }

        async void OnLoginButtonClicked(object sender, EventArgs e)
        {
            //Validates email
            if (!HalliganUtils.IsValidEmail(entryEmail.Text))
            {
                await DisplayAlert(AppResources.error_title, 
                    AppResources.login_page_email_validation_error, 
                    AppResources.accept_button_text);
                return;
            }
            //Validates password
            if (!HalliganUtils.IsValidPassword(entryPassword.Text))
            {
                await DisplayAlert(AppResources.error_title,
                    AppResources.login_page_password_validation_error,
                    AppResources.accept_button_text);
                return;
            }
            HalliganCredential credentials = new HalliganCredential
            {
                Email = entryEmail.Text,
                Password = entryPassword.Text
            };

            await App.RestClient.GetUserAuthAsync(credentials)
                .OnSuccess((result) =>
                {
                    Navigation.InsertPageBefore(new MainPage(), this);
                    Navigation.PopAsync();
                })
                .OnRequestStarted(() =>
                {
                    activityIndicator.IsRunning = true;
                    entryEmail.IsEnabled = false;
                    entryPassword.IsEnabled = false;
                })
                .OnRequestCompleted(() =>
                {
                    activityIndicator.IsRunning = false;
                    entryEmail.IsEnabled = true;
                    entryPassword.IsEnabled = true;
                })
                .OnHttpError((exception) =>
                {
                    DisplayAlert(AppResources.error_title, 
                        AppResources.login_page_login_failed_message, 
                        AppResources.accept_button_text);
                })
                .OnUnknownError((exception) =>
                {
                    DisplayAlert(AppResources.error_title,
                        AppResources.unknown_error,
                        AppResources.accept_button_text);
                })
                .Start();
        }

    }
}

更新

我尝试更改方法签名但不起作用。我尝试了什么:

public async void OnForgotPasswordClicked(object sender, EventArgs e)

public void OnForgotPasswordClicked(object sender, EventArgs e)

0 个答案:

没有答案