名称' InitializeComponent'在当前上下文中不存在(Visual Studio 2017)

时间:2017-11-27 02:50:12

标签: c# xamarin.forms visual-studio-2017

我在尝试编译应用程序时已经遇到了这个问题大约三天了。 Visual Studio不断突出显示该代码

public partial class ProfileView : ContentPage
{
    public ProfileView()
    {
        InitializeComponent();
    }     
  }

错误消息:

  

名称' InitializeComponent'在当前上下文中不存在

以上代码位于profileViewModel.xaml.cs后面的代码中 以下是我的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"
             x:Class="CladMallApp.Core.Views.ProfileView"
             xmlns:viewModelBase="clr-namespace:CladMallApp.Core.ViewModels.Base;assembly=CladMallApp.Core"
             xmlns:animations="clr-namespace:CladMallApp.Core.Animations;assembly=CladMallApp.Core"
             xmlns:converters="clr-namespace:CladMallApp.Core.Converters;assembly=CladMallApp.Core"
             xmlns:triggers="clr-namespace:CladMallApp.Core.Triggers;assembly=CladMallApp.Core"
             xmlns:templates="clr-namespace:CladMallApp.Core.Views.Templates;assembly=CladMallApp.Core"
             xmlns:behaviors="clr-namespace:CladMallApp.Core.Behaviors;assembly=CladMallApp.Core"
             viewModelBase:ViewModelLocator.AutoWireViewModel="true"
             Title="My Profile">
    <ContentPage.Resources>
        <ResourceDictionary>

            <Style x:Key="LoginButtonStyle" 
               TargetType="{x:Type Label}">
                <Setter Property="FontFamily"
                        Value="{StaticResource MontserratRegular}" />
                <Setter Property="TextColor"
                        Value="{StaticResource WhiteColor}" />
                <Setter Property="HorizontalOptions"
                        Value="Center" />
                <Setter Property="VerticalOptions"
                        Value="Center" />
            </Style>

            <Style x:Key="MyOrdersLabelStyle" 
               TargetType="{x:Type Label}">
                <Setter Property="FontFamily"
                        Value="{StaticResource MontserratRegular}" />
                <Setter Property="FontSize"
                        Value="{StaticResource MediumSize}" />
                <Setter Property="HorizontalOptions"
                        Value="Center" />
                <Setter Property="VerticalOptions"
                        Value="Center" />
                <Setter Property="Margin"
                        Value="0, 12" />
            </Style>

        </ResourceDictionary>
    </ContentPage.Resources>
    <Grid    
        Padding="0"     
        ColumnSpacing="0"   
        RowSpacing="0"
        BackgroundColor="{StaticResource BackgroundColor}">
        <Grid.RowDefinitions>
            <RowDefinition Height="60" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <!-- LOG OUT BUTTON -->
        <Button         
            Grid.Row="0"
            Text="LOG OUT" 
            TextColor="{StaticResource BlackColor}"
            BackgroundColor="{StaticResource GrayColor}"
            Command="{Binding LogoutCommand}" />
        <!-- ORDERS -->
        <Grid
            Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Label 
                Grid.Row="0"
                Text="MY ORDERS"
                Style="{StaticResource MyOrdersLabelStyle}"/>
            <Grid 
                Grid.Row="1">
                <Grid 
                    IsVisible="{Binding IsBusy, Converter={StaticResource InverseBoolConverter}}">
                    <Label 
                        Text="NO ORDERS"      
                        IsVisible="{Binding Orders.Count, Converter={StaticResource InverseCountToBoolConverter}}"
                        HorizontalOptions="Center"
                        VerticalOptions="Center"/>
                </Grid>
                <ListView 
                    ItemsSource="{Binding Orders}"
                    HasUnevenRows="True"
                    SeparatorVisibility="None"
                    CachingStrategy="RecycleElement">
                    <ListView.Behaviors>
                        <behaviors:EventToCommandBehavior           
                            EventName="ItemTapped"
                            Command="{Binding OrderDetailCommand}"
                            EventArgsConverter="{StaticResource ItemTappedEventArgsConverter}" />
                    </ListView.Behaviors>


                </ListView>
            </Grid>
        </Grid>
    </Grid>
</ContentPage>`

我已经查看过,文件似乎没有遗漏任何内容。我做错了什么?

0 个答案:

没有答案