2016-09-30 2 views
0

내 xaml 페이지에서 absolut에서 stacklayout으로 레이아웃을 변경하기로 결정한 후 내 앱이 실행될 때 nullre .. 예외가 발생했습니다. 나는 한 페이지에서 다른 페이지의 모든 요소들, 심지어 stacklayout에 댓글을 달았지만 여전히 오류가있다. 처음에는 호출 스택을 사용하려고했지만 유용 할 수있는 것을 볼 수 없습니다. 내 페이지를 변경하기 전에 모든 것이 잘 작동하고있었습니다. 또한 MasterDetailPage의 마스터 페이지입니다. Xaml.cs 파일이 비어 있습니다. ** ` 이상한 NullReferenceException 및 쓸모없는 호출 스택

<!--Header--> 
<BoxView x:Name="GrayHeader" 
     Style="{StaticResource GrayBoxView}" 
     AbsoluteLayout.LayoutBounds="{Binding MasterProfileGrayHeaderBounds}" 
     AbsoluteLayout.LayoutFlags="All"> 
</BoxView> 

<Image x:Name="MasterProfileImage" 
     WidthRequest="50" 
     HeightRequest="50" 
     Source="ic_account_circle_white_24dp.png" 
     AbsoluteLayout.LayoutBounds="{Binding MasterProfileImageBounds}" 
     AbsoluteLayout.LayoutFlags="None"> 
</Image> 

<Label x:Name="MasterProfileName" 
     Text="GitRemote" 
     FontAttributes="Bold" 
     FontSize="18" 
     AbsoluteLayout.LayoutBounds="{Binding MasterProfileNameBounds}" 
     AbsoluteLayout.LayoutFlags="None"> 
</Label> 

<!--Body--> 

<ListView x:Name="MasterPageMenu" 
      SeparatorColor="Transparent" 
      AbsoluteLayout.LayoutBounds="{Binding MasterMenuBounds}" 
      AbsoluteLayout.LayoutFlags="None" 
      ItemsSource="{Binding MenuItems}" 
      SelectedItem="{Binding MenuItemSelectedProperty, Mode=TwoWay}"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
      <ViewCell> 
       <StackLayout Orientation="Horizontal" Spacing="15" Padding="10" > 
        <Label Text="{Binding Name}" FontSize="16" VerticalOptions="Center" FontAttributes="Bold"/> 
        <Image Source="{Binding ImageSource}" WidthRequest="25" HeightRequest="25" /> 
       </StackLayout> 
      </ViewCell> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
    <b:Interaction.Behaviors> 
     <b:BehaviorCollection> 
     <b:EventToCommand EventName="ItemSelected" Command="{Binding MenuItemSelected}"></b:EventToCommand> 
     </b:BehaviorCollection> 
    </b:Interaction.Behaviors> 
</ListView> 
다음

지금 내 뷰 모델입니다 :

전에 모습

<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:b="clr-namespace:Xamarin.Behaviors;assembly=Xamarin.Behaviors" 
       prism:ViewModelLocator.AutowireViewModel="True" 
       x:Class="GitRemote.Views.MasterPage" 
       Title="Necessary"> 

     <!--<StackLayout x:Name="MasterMenu" 
        HorizontalOptions="StartAndExpand" 
        VerticalOptions="StartAndExpand"> 

     --><!--<BoxView x:Name="GrayHeader" 
       Color="#CACED2" 
       HorizontalOptions="StartAndExpand" 
       VerticalOptions="Start" 
       HeightRequest="100"/>--><!-- 


     --><!--<Image x:Name="MasterProfileImage" 
       WidthRequest="50" 
       HeightRequest="50" 
       Source="ic_account_circle_white_24dp.png" 
       HorizontalOptions="Start" 
       VerticalOptions="Start" 
       Margin="15, 15, 0, 0"/>--><!-- 

     --><!--<Image x:Name="LogOutImage" 
       WidthRequest="45" 
       HeightRequest="45" 
       Source="ic_menu_logout.png" 
       HorizontalOptions="End" 
       VerticalOptions="Start" 
       Margin="0, 15, 15, 0"/>--><!-- 

     --><!--<Label x:Name="MasterProfileName" 
       Text="GitRemote" 
       FontAttributes="Bold" 
       FontSize="18" 
       HorizontalOptions="Start" 
       VerticalOptions="Start" 
       TextColor="Black" 
       Margin="15, 80, 0, 0"/>--><!-- 


     --><!--<ListView x:Name="MasterPageMenu" 
        SeparatorColor="Transparent" 
        HorizontalOptions="Start" 
        VerticalOptions="Start" 
        Margin="15, 120, 0, 0" 
        ItemsSource="{Binding MenuItems}" 
        SelectedItem="{Binding MenuItemSelectedProperty, Mode=TwoWay}"> 
      <ListView.ItemTemplate> 
      <DataTemplate> 
       <ViewCell> 
       <StackLayout Orientation="Horizontal" 
          Spacing="15" 
          Padding="10" > 
        <Label Text="{Binding Name}" 
         FontSize="16" 
         VerticalOptions="Center" 
         FontAttributes="Bold"/> 
        <Image Source="{Binding ImageSource}" 
         WidthRequest="25" 
         HeightRequest="25" /> 
       </StackLayout> 
       </ViewCell> 
      </DataTemplate> 
      </ListView.ItemTemplate> 
      <b:Interaction.Behaviors> 
      <b:BehaviorCollection> 
       <b:EventToCommand EventName="ItemSelected" 
           Command="{Binding MenuItemSelected}"></b:EventToCommand> 
      </b:BehaviorCollection> 
      </b:Interaction.Behaviors> 
     </ListView>--><!-- 

     </StackLayout>--> 

    </ContentPage>` 

이 ** 이것은 : 여기 지금 XAML입니다

using GitRemote.Models; 
using Prism.Commands; 
using Prism.Mvvm; 
using Prism.Navigation; 
using System.Collections.ObjectModel; 

namespace GitRemote.ViewModels 
{ 
public class MasterPageViewModel : BindableBase 
{ 

    #region Constants 
    private const string GistsPageImagePath = "ic_code_black_24dp.png"; 
    private const string IssueDashboardPageImagePath = "ic_slow_motion_video_black_24dp.png"; 
    private const string BookmarksPageImagePath = "ic_bookmark_black_24dp.png"; 
    private const string ReportAnIssuePageImagePath = "ic_error_outline_black_24dp.png"; 
    #endregion 

    //#region Bindable properties 
    //private Rectangle _masterProfileGrayHeaderBounds; 

    //public Rectangle MasterProfileGrayHeaderBounds 
    //{ 
    // get { return _masterProfileGrayHeaderBounds; } 
    // set { SetProperty(ref _masterProfileGrayHeaderBounds, value); } 
    //} 

    //private Rectangle _masterProfileImageBounds; 

    //public Rectangle MasterProfileImageBounds 
    //{ 
    // get { return _masterProfileImageBounds; } 
    // set { SetProperty(ref _masterProfileImageBounds, value); } 
    //} 

    //private Rectangle _masterProfileNameBounds; 

    //public Rectangle MasterProfileNameBounds 
    //{ 
    // get { return _masterProfileNameBounds; } 
    // set { SetProperty(ref _masterProfileNameBounds, value); } 
    //} 

    //private Rectangle _masterMenuBounds; 

    //public Rectangle MasterMenuBounds 
    //{ 
    // get { return _masterMenuBounds; } 
    // set { SetProperty(ref _masterMenuBounds, value); } 
    //} 

    //private MasterPageMenuItemModel _menuItemSelectedProperty; 

    //public MasterPageMenuItemModel MenuItemSelectedProperty 
    //{ 
    // get { return _menuItemSelectedProperty; } 
    // set { SetProperty(ref _menuItemSelectedProperty, value); } 
    //} 
    ////#endregion 

    //private readonly INavigationService _navigationService; 

    //public ObservableCollection<MasterPageMenuItemModel> MenuItems; 

    //public DelegateCommand MenuItemSelected; 

    public MasterPageViewModel() 
    { 
     //_navigationService = navigationService; 
     //MenuItemSelected = new DelegateCommand(OnMenuItemSelected); 

     //MasterProfileGrayHeaderBounds = new Rectangle(0, 0, 1, 0.175); 
     //MasterProfileImageBounds = new Rectangle(16, 16, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize); 
     //MasterProfileNameBounds = new Rectangle(16, 70, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize); 
     //MasterMenuBounds = new Rectangle(16, 100 + 10, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize); 

     //MenuItems = new ObservableCollection<MasterPageMenuItemModel> 
     //{ 
     // new MasterPageMenuItemModel {Name = "GistsPage", ImageSource = GistsPageImagePath}, 
     // new MasterPageMenuItemModel {Name = "IssueDashboardPage", ImageSource = IssueDashboardPageImagePath}, 
     // new MasterPageMenuItemModel {Name = "BookmarksPage", ImageSource = BookmarksPageImagePath}, 
     // new MasterPageMenuItemModel {Name = "ReportAnIssuePage", ImageSource = ReportAnIssuePageImagePath} 
     //}; 
    } 

    //private void OnMenuItemSelected() 
    //{ 
    // if (MenuItemSelectedProperty == null) return; 
    // _navigationService.NavigateAsync(MenuItemSelectedProperty.Name, animated: false); 
    // MenuItemSelectedProperty = null; 
    //} 
} 
} 

그리고 전에 :

using GitRemote.Models; 
using Prism.Commands; 
using Prism.Mvvm; 
using Prism.Navigation; 
using System.Collections.ObjectModel; 
using Xamarin.Forms; 

namespace GitRemote.ViewModels 
{ 
public class MasterPageViewModel : BindableBase 
{ 

    #region Constants 
    private const string GistsPageImagePath = "ic_code_black_24dp.png"; 
    private const string IssueDashboardPageImagePath = "ic_slow_motion_video_black_24dp.png"; 
    private const string BookmarksPageImagePath = "ic_bookmark_black_24dp.png"; 
    private const string ReportAnIssuePageImagePath = "ic_error_outline_black_24dp.png"; 
    #endregion 

    #region Bindable properties 
    private Rectangle _masterProfileGrayHeaderBounds; 

    public Rectangle MasterProfileGrayHeaderBounds 
    { 
     get { return _masterProfileGrayHeaderBounds; } 
     set { SetProperty(ref _masterProfileGrayHeaderBounds, value); } 
    } 

    private Rectangle _masterProfileImageBounds; 

    public Rectangle MasterProfileImageBounds 
    { 
     get { return _masterProfileImageBounds; } 
     set { SetProperty(ref _masterProfileImageBounds, value); } 
    } 

    private Rectangle _masterProfileNameBounds; 

    public Rectangle MasterProfileNameBounds 
    { 
     get { return _masterProfileNameBounds; } 
     set { SetProperty(ref _masterProfileNameBounds, value); } 
    } 

    private Rectangle _masterMenuBounds; 

    public Rectangle MasterMenuBounds 
    { 
     get { return _masterMenuBounds; } 
     set { SetProperty(ref _masterMenuBounds, value); } 
    } 

    private MasterPageMenuItemModel _menuItemSelectedProperty; 

    public MasterPageMenuItemModel MenuItemSelectedProperty 
    { 
     get { return _menuItemSelectedProperty; } 
     set { SetProperty(ref _menuItemSelectedProperty, value); } 
    } 
    #endregion 

    private readonly INavigationService _navigationService; 

    public ObservableCollection<MasterPageMenuItemModel> MenuItems; 

    public DelegateCommand MenuItemSelected; 

    public MasterPageViewModel(INavigationService navigationService) 
    { 
     _navigationService = navigationService; 
     MenuItemSelected = new DelegateCommand(OnMenuItemSelected); 

     MasterProfileGrayHeaderBounds = new Rectangle(0, 0, 1, 0.175); 
     MasterProfileImageBounds = new Rectangle(16, 16, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize); 
     MasterProfileNameBounds = new Rectangle(16, 70, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize); 
     MasterMenuBounds = new Rectangle(16, 100 + 10, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize); 

     MenuItems = new ObservableCollection<MasterPageMenuItemModel> 
     { 
      new MasterPageMenuItemModel {Name = "GistsPage", ImageSource = GistsPageImagePath}, 
      new MasterPageMenuItemModel {Name = "IssueDashboardPage", ImageSource = IssueDashboardPageImagePath}, 
      new MasterPageMenuItemModel {Name = "BookmarksPage", ImageSource = BookmarksPageImagePath}, 
      new MasterPageMenuItemModel {Name = "ReportAnIssuePage", ImageSource = ReportAnIssuePageImagePath} 
     }; 
    } 

    private void OnMenuItemSelected() 
    { 
     if (MenuItemSelectedProperty == null) return; 
     _navigationService.NavigateAsync(MenuItemSelectedProperty.Name, animated: false); 
     MenuItemSelectedProperty = null; 
    } 
} 
} 

나는 모든 물건을 주석하고 occuers 내가 왜 아무 생각이 어디서.

이미지가 내 통화 스택입니다. 그러나 나는 그것이 무엇을 의미하는지 모른다. 그리고 나는 그것으로 무엇이든 할 수 없다. enter image description here

답변

0

프리즘에서 현재보기 모델의 매개 변수를 보내면 탐색하는 페이지의 모델을 볼 수 있습니다. 그래서 매개 변수를 보내고 다른 쪽에서는 그들을 가져 가고있었습니다. 하지만 전화하기 전에 그 존재를 확인하지는 않았습니다. 그래서 NullReferenceException이 발생했습니다.

관련 문제