Xamarin.iOS错误-应用程序窗口应具有根视图控制器....使用静态绑定

时间:2019-07-05 00:48:03

标签: xaml binding xamarin.ios

我收到此错误:

  

Foundation.MonoTouchException:引发Objective-C异常。名称:   NSInternalInconsistencyExceptionException原因:应用程序窗口是   预计在应用程序末尾具有根视图控制器   发射

如果我在xaml文件中使用这种绑定,请使用Xamarin.iOS:

<?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:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             xmlns:converters="clr-namespace:AppAlgorix.Converters"
             xmlns:resources="clr-namespace:AppAlgorix.Resources"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="AppAlgorix.Views.LoginPage">

    <ContentPage.Resources>
        <ResourceDictionary>
            <converters:MaskedCardConverter x:Key="cvtMaskedCard"></converters:MaskedCardConverter>
        </ResourceDictionary>
    </ContentPage.Resources>
    <ContentPage.Content>
        <StackLayout Orientation="Vertical" HorizontalOptions="Center" Padding="20">
            <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="Fill" HeightRequest="80">
                 <Label Text="SEJA BEM VINDO" HorizontalOptions="CenterAndExpand" FontSize="Large" FontAttributes="None" TextColor="{Binding Source={x:Static resources:AppParameters.AppLabelColorDefault}}"></Label>
            </StackLayout>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

我也尝试过这种格式:

<Label Text="SEJA BEM VINDO" HorizontalOptions="CenterAndExpand"
FontSize="Large" FontAttributes="None" TextColor="{Binding
AppLabelColorDefault, Source={x:Static
resources:AppParameters}}"></Label>

我的参数类是这样:

namespace AppAlgorix.Resources
{
    public static class AppParameters
    {
        public static string AppLabelColorDefault
        {
            get
            {
                var color = Parameters.ResourceManager.GetString("applabelcolordefault");
                return color;
            }
        }
    }
}

我的Xamarin项目具有Android和iOS。这种方法适用于Android,但不适用于iOS。

如果我改变看法:

<?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:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             xmlns:converters="clr-namespace:AppAlgorix.Converters"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="AppAlgorix.Views.LoginPage">

    <ContentPage.Resources>
        <ResourceDictionary>
            <converters:MaskedCardConverter x:Key="cvtMaskedCard"></converters:MaskedCardConverter>
        </ResourceDictionary>
    </ContentPage.Resources>

    <ContentPage.Content>
        <StackLayout Orientation="Vertical" HorizontalOptions="Center" Padding="20">
            <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="Fill" HeightRequest="80">
                <Label Text="SEJA BEM VINDO" HorizontalOptions="CenterAndExpand" FontSize="Large" FontAttributes="None" TextColor="Black"></Label>
            </StackLayout>
        </StackLayout>
    </ContentPage.Content>

</ContentPage>

我可以执行并在模拟器中查看我的视图...

所以,我认为我的问题是这种绑定格式...

我的问题是...如何在Xamarin.iOS中解决此错误,而又不破坏Xamarin.Android?

0 个答案:

没有答案