在'System.Windows.Baml2006.TypeConverterMarkupExtension'上提供值为MessageBox引发异常

时间:2013-05-18 11:19:01

标签: c#

我面临着上述错误的可怕问题。我正在开发一个WPF应用程序,我只是想为我的应用程序显示一个自定义的消息框。所以我在参考中包含了ExtendedWPF工具包。我已经在App.Xaml中声明了Messagebox的样式。如下:

<!--MessageBox Style-->
        <SolidColorBrush x:Key="MyButtonHoverBrush" Color="Firebrick"/>
        <SolidColorBrush x:Key="MyButtonPressedBrush" Color="DarkRed"/>
        <Style x:Key="MyCloseButtonStyle" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00:0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background)">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource MyButtonHoverBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00:0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background)">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource MyButtonPressedBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="Background" CornerRadius="0,0,2,0" Background="Blue">
                                <Border Margin="1,0,1,1" Background="Green" BorderThickness="1" CornerRadius="0,0,1,0"/>
                            </Border>
                            <ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
                            <Path x:Name="path" Fill="Red" Margin="0,0,0,1" Visibility="Collapsed" Height="6" Width="7" Stretch="Fill" Opacity="1" 
                                Data="M 2,6 C2,6 3,6 3,6 3,6 3,5 3,5 3,5 4,5 4,5 4,5 4,6 4,6 4,6 5,6 5,6 5,6 7,6 7,6 7,6 7,5 7,5 7,5 6,5 6,5 6,5 6,4 6,4 6,4 5,4 5,4 5,4 5,2 5,2 5,2 6,2 6,2 6,2 6,1 6,1 6,1 7,1 7,1 7,1 7,0 7,0 7,0 5,0 5,0 5,0 4,0 4,0 4,0 4,1 4,1 4,1 3,1 3,1 3,1 3,0 3,0 3,0 2,0 2,0 2,0 0,0 0,0 0,0 0,1 0,1 0,1 1,1 1,1 1,1 1,2 1,2 1,2 2,2 2,2 2,2 2,4 2,4 2,4 1,4 1,4 1,4 1,5 1,5 1,5 0,5 0,5 0,5 0,6 0,6 0,6 2,6 2,6 z"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="{x:Type controls:MessageBox}">
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Yellow" Offset="0"/>
                    <GradientStop Color="Tomato" Offset="0.543"/>
                    <GradientStop Color="Turquoise" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="WindowOpacity" Value="0.7"/>
        <Setter Property="Height" Value="170"/>
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="CaptionForeground" Value="White"/>
        <Setter Property="WindowBorderBrush" Value="Blue"/>
        <Setter Property="WindowBackground">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Blue" Offset="0.014"/>
                    <GradientStop Color="Blue" Offset="1"/>
                    <GradientStop Color="White" Offset="0.514"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="CloseButtonStyle" Value="{StaticResource MyCloseButtonStyle}"/>
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="FontFamily" Value="Palatino Linotype"/>
        <Setter Property="FontSize" Value="15"/>
        <Setter Property="FontWeight" Value="Bold"/>

    </Style>

我在全局类中声明了MessageBox,它传递了一串消息,如下所示:

 public static void msgWarning(string msg)
        {
            string caption = "Warning";
            MessageBoxButton btn= MessageBoxButton.OK;
            MessageBoxImage img = MessageBoxImage.Warning;

            MessageBoxResult res = Microsoft.Windows.Controls.MessageBox.Show(msg, caption, btn, img);

        }

但是当我引用样式时,我在MessageBox的调用期间在MessageBoxResult Line中得到了所提到的错误。但是如果我评论Style然后执行MessageBox就会显示出来。

请帮我解决这个问题。

先谢谢。

0 个答案:

没有答案