XAML文件无法创建实例对象?

时间:2014-05-19 08:07:12

标签: c# wpf xaml mahapps.metro

尝试创建身份验证对话框而不修改mahapps metro的内部工作方式。

我基于MahApps.Metro.Controls.Dialogs.InputDialog创建了对话框窗口,但出现错误:“异常:无法创建”BaseMetroDialog“的实例。”

XAML文件如下:

<Dialogs:BaseMetroDialog xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                         xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
                         x:Class="MahApps.Metro.Controls.Dialogs.InputDialog"
                         Loaded="Dialog_Loaded">
    <Dialogs:BaseMetroDialog.DialogBody>
        <Grid Margin="0 10 0 0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"
                               MinHeight="20" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0"
                       Margin="0 5 0 0"
                       FontSize="15"
                       Text="{Binding Message, RelativeSource={RelativeSource AncestorType=Dialogs:InputDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
                       TextWrapping="Wrap"
                       Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Dialogs:InputDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}" />
            <TextBox Grid.Row="1"
                     Margin="0 5 0 0"
                     FontSize="15"
                     x:Name="PART_TextBox"
                     Text="{Binding Input, RelativeSource={RelativeSource AncestorType=Dialogs:InputDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
                     TextWrapping="Wrap"
                     Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Dialogs:InputDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}" />

            <StackPanel Grid.Row="2"
                        Orientation="Horizontal"
                        HorizontalAlignment="Right"
                        Height="85">
                <Button x:Name="PART_AffirmativeButton"
                        Height="35"
                        MinWidth="80"
                        Style="{DynamicResource AccentedDialogSquareButton}"
                        Content="{Binding AffirmativeButtonText, RelativeSource={RelativeSource AncestorType=Dialogs:InputDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
                        Margin="0 0 5 0" />
                <Button x:Name="PART_NegativeButton"
                        Height="35"
                        MinWidth="80"
                        Content="{Binding NegativeButtonText, RelativeSource={RelativeSource AncestorType=Dialogs:InputDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
                        Margin="5 0 5 0" />
            </StackPanel>
        </Grid>
    </Dialogs:BaseMetroDialog.DialogBody>
</Dialogs:BaseMetroDialog>

以下是错误输出:

StackTrace:
at Microsoft.Expression.Platform.InstanceBuilders.InstanceBuilderOperations.InstantiateType(Type type, Boolean supportInternal)
   at Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.InstantiateTargetType(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.Expression.WpfPlatform.InstanceBuilders.FrameworkElementInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.Expression.Platform.InstanceBuilders.ViewNodeManager.CreateInstance(IInstanceBuilder builder, ViewNode viewNode)

InnerException: Object reference not set to an instance of an object.
    NullReferenceException: Object reference not set to an instance of an object.
TargetInvocationException: Exception has been thrown by the target of an invocation.
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)

0 个答案:

没有答案