2012-08-22 1 views
0

que je reçois une exception non gérée lors du chargement du concepteur (VS2010)Erreur de chargement WPF Designer (System.NullReferenceException) MahApps.Metro.Controls

Ce sont les détails.

System.NullReferenceException 
Object reference not set to an instance of an object. 
at MahApps.Metro.Controls.TextboxHelper.TextBoxLoaded(Object sender, RoutedEventArgs e) 
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) 
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) 
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent) 
at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root) 
at MS.Internal.LoadedOrUnloadedOperation.DoWork() 
at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks() 
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() 
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) 
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) 
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 

J'ai essayé

--commenting toutes les zones de texte

--commenting sur tout le code dans mon constructeur viewmodel

--commenting la création de MainWindowVieWModel dans le constructeur MainWindow Je suis déconcerté ..

code ...

public partial class MainWindow : MetroWindow 
{ 
    public MainWindowViewModel ViewModel { get; protected set; } 

    public MainWindow() 
    { 
     ViewModel = new MainWindowViewModel(new AppModel()); 
     InitializeComponent(); 
    } 


public class AppModel : ReactiveValidatedObject 
{ 
    public ReactiveCollection<SheetModel> CompletedSheets { get; protected set; } 

    public void RefreshData() 
    { 
     List<SheetModel> sheets = DataLayer.LoadData(); 

     CompletedSheets = new ReactiveCollection<SheetModel>(); 

     foreach (var sheetModel in sheets) 
     { 
      CompletedSheets.Add(sheetModel); 
     } 
    } 

    public AppModel() 
    { 
     CompletedSheets = new ReactiveCollection<SheetModel>(); 
    } 

Constructor pour le modèle principal affichage de la fenêtre est vide, donc ne devrait pas y avoir de problème.

MainWindowXaml ...

<Controls:MetroWindow 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
x:Class="TimeSheet.MainWindow" 
Title="MainWindow" 
x:Name="Window" 
Height="270" 
MinWidth="490" 
Width="600" 
xmlns:local="clr-namespace:TimeSheet" 
ShowTitleBar="False" WindowStartupLocation="CenterScreen" 
DataContext="{Binding ViewModel, ElementName=Window}"> 

<Controls:MetroWindow.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 

     <DataTemplate x:Key="CompletedBlockTile"> 
      <StackPanel Orientation="Vertical" Margin="10,0,0,0"> 
       <TextBlock Text="{Binding Date}" FontWeight="Bold" FontFamily="Segoe UI" /> 
      </StackPanel> 
     </DataTemplate> 

     <DataTemplate x:Key="TaskTemplate"> 
      <Grid HorizontalAlignment="Stretch"> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition MinWidth="80px"/> 
        <ColumnDefinition Width="50px" /> 
        <ColumnDefinition Width="40px"/> 
        <ColumnDefinition Width="40px"/> 
       </Grid.ColumnDefinitions> 

       <TextBlock Grid.Column="0" Text="{Binding Description}" Height="25.3" Margin="0" HorizontalAlignment="Stretch"/> 
       <TextBlock Grid.Column="1" Text="{Binding Duration}" Margin="0,0,0,0" Height="25.3" Width="45.625"/> 
       <Button Grid.Column="2" Content="&gt;&gt;" HorizontalAlignment="Right" Width="38" Command="{Binding ReStartCommand}"/> 
       <Button Grid.Column="3" Content="STOP" VerticalAlignment="Top" Margin="0,0,0,0" Command="{Binding StopCommand}" HorizontalAlignment="Right" Width="35"/> 
      </Grid> 
     </DataTemplate> 

     <BitmapImage x:Key="SearchImage" UriSource="Images/blue-37.png" /> 
    </ResourceDictionary> 

</Controls:MetroWindow.Resources> 

<Controls:MetroWindow.WindowCommands> 
    <Controls:WindowCommands> 
     <Button x:Name="thisButton"> 
      <StackPanel Orientation="Horizontal"> 
       <StackPanel Orientation="Horizontal"> 

        <Label Margin="0,0,55,0" Content="09:00"/> 
        <Label Margin="0,0,5,0" Content="Friday 20th July 2012"/> 

        <TextBox Controls:TextboxHelper.Watermark="search" 
           Controls:TextboxHelper.ClearTextButton="True" 
           VerticalAlignment="Top" 
           HorizontalAlignment="Left" 
           Width="154.002" /> 

        <Button Style="{DynamicResource ChromelessButtonStyle}" Click="Button_Click"> 
         <Image Source="{StaticResource SearchImage}" Width="20"/> 
        </Button> 

       </StackPanel> 
      </StackPanel> 
     </Button> 
    </Controls:WindowCommands> 
</Controls:MetroWindow.WindowCommands> 

<DockPanel Margin="0,0,0,0" > 
    <DockPanel DockPanel.Dock="Left" Margin="0,0,0,0" Width="176.625" > 

     <ListBox Background="Transparent" 
       BorderBrush="Transparent" 
       Margin="0,30,0,0" 
       ItemsSource="{Binding CompletedSheets}" 
       ItemTemplate="{DynamicResource CompletedBlockTile}" 
       SelectedItem="{Binding SelectedTimeSheet}"/> 


    </DockPanel> 
    <DockPanel DockPanel.Dock="Right" > 
     <Grid Margin="0,30,0,0" VerticalAlignment="Top" DockPanel.Dock="Top"> 
      <Grid Margin="0,0,14,0.805"> 

       <local:TextBoxChangeExt 
        MinWidth="200" 
         Controls:TextboxHelper.Watermark="Task Name" 
         Controls:TextboxHelper.ClearTextButton="True" 
         d:LayoutOverrides="Height" 
         Margin="8,0,70,0" 
         Background="{x:Null}" 
        Text="{Binding NewTaskName}"> 

       </local:TextBoxChangeExt> 

       <Button HorizontalAlignment="Right" 
         Width="57" 
         d:LayoutOverrides="HorizontalAlignment, Height" 
         Content="Start" 
         Command="{Binding StartCommand}" IsEnabled="{Binding StartNewEnabled}"/> 

      </Grid> 
     </Grid> 
     <Grid DockPanel.Dock="Bottom"> 
      <ListBox Margin="8,8,5,5" 

        BorderBrush="{x:Null}" 
        ItemTemplate="{DynamicResource TaskTemplate}" 
        ItemsSource="{Binding SelectedTimeSheet.Tasks}" 
        HorizontalContentAlignment="Stretch" 
        /> 
     </Grid> 


    </DockPanel> 
</DockPanel> 

+0

Vous avez défini un contrôle 'local: TextBoxChangeExt' dans l'arbre visuel - sans les détails de ce comportement qu'il contient, je ne peux pas vous aider à identifier la cause de ce problème . –

Répondre

0

Je suis assez sûr que ce soit un bug. J'obtiens la même erreur, et en suivant la pile-trace à la ligne dans mon ViewModel, je vois que je vérifie de manière appropriée pour null. Tout semble fonctionner pendant l'exécution, mais je pense que c'est un bug lors de l'utilisation des implimations d'iCommand dans le concepteur. Dites-nous si vous avez trouvé votre cause différente.

J'utilise aussi VS 2010.

+0

Je n'ai pas joué avec ça récemment ... une joie pour toi? –

+0

J'ai effectivement trouvé mon erreur. Dans mon cas, lors de la conception, j'avais un objet null dans mon CanExecute où j'essayais d'accéder à une propriété de l'objet. Pour moi, une fois que j'ai compris, le correctif était évident, il suffit d'ajouter un NullCheck avant de vérifier la propriété qui m'intéressait semblait résoudre ce problème (c'est-à-dire MyObj! = Null && MyObj.MyBoolProp). – William