デザイナーをロードするときに未処理の例外が発生します (VS2010)
これらは詳細です。
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)
私が試してみました
-- すべてのテキスト ボックスをコメント アウトします。
-- ビューモデル コンストラクターのすべてのコードをコメント アウトする
-- MainWindow コンストラクターでの MainWindowVieWModel の作成をコメントアウトしています...
私は当惑しています..
コード...
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>();
}
メイン ウィンドウ ビュー モデルのコンストラクターは空であるため、問題はありません。
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=">>" 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>