3

I am getting this error when I go to open my WPF window and I have no idea what created the error or how to get rid of it. The error is highlighting and pointing to </Border> at the bottom.

'Initialization of 'Outlook_Add_In_Test.WPFExiEvent' threw an exception.' Line number '91' and line position '11'.

My WPF Code:

<Controls:MetroWindow x:Class="Outlook_Add_In_Test.WPFExiEvent"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
             xmlns:System="clr-namespace:System;assembly=mscorlib" 
             mc:Ignorable="d" d:DesignWidth="550" MaxHeight="640" MaxWidth="550" Title="Search for an Existing Event" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Height="340" HorizontalAlignment="Center" VerticalAlignment="Center">

    <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="Theme/Test.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
                <ResourceDictionary Source="Theme/FlatButton.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Controls:MetroWindow.Resources>

    <Border BorderBrush="Black" BorderThickness="1">
        <Grid Margin="0,0,0,-1">


            <Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="1" Margin="6,108,0,0" VerticalAlignment="Top" Width="524" Opacity="0.2" RenderTransformOrigin="0.5,0.5">
                <Border.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleY="-1"/>
                        <SkewTransform/>
                        <RotateTransform/>
                        <TranslateTransform/>
                    </TransformGroup>
                </Border.RenderTransform>
            </Border>

            <Image x:Name="ImgDefactoLogo" HorizontalAlignment="Left" Height="36" Margin="10,10,0,0" VerticalAlignment="Top" Width="43" Source="Images/DeFactoERP.ico"/>
            <Image x:Name="ImgAttachmentType" HorizontalAlignment="Left" Margin="65,10,0,0" Width="32" RenderTransformOrigin="0.143,0.778" Height="36" VerticalAlignment="Top"/>
            <Label Content="Search for an Existing Event" HorizontalAlignment="Left" Height="36" Margin="97,19,0,0" VerticalAlignment="Top" Width="259" FontSize="16" FontFamily="Arial" FontWeight="Bold"/>
            <TextBlock x:Name="LblInfo"  HorizontalAlignment="Left" Height="47" Margin="10,60,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="524" FontSize="15" FontFamily="Arial" Text="Please search for an existing event in your De Facto ERP system that you want to use for adding the attachment to."/>
            <Label Content="Event No:" HorizontalAlignment="Left" Height="43" Margin="7,126,0,0" VerticalAlignment="Top" Width="112" FontSize="16" FontFamily="Arial" FontWeight="Bold" Foreground="Black"/>
            <Label Content="Event Subject:" HorizontalAlignment="Left" Height="43" Margin="7,164,0,0" VerticalAlignment="Top" Width="119" FontSize="16" FontFamily="Arial" FontWeight="Bold"/>
            <TextBox x:Name="TxtEventNo" HorizontalAlignment="Left" Height="33" Margin="151,126,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="200" ToolTip="Enter Event Number..." KeyDown="TxtEventNo_KeyDown" TextChanged="TxtEventNo_TextChanged"/>
            <TextBox x:Name="TxtSubject" HorizontalAlignment="Left" Height="33" Margin="151,164,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="200" KeyDown="TxtSubject_KeyDown" TextChanged="TxtSubject_TextChanged"/>
            <Label Content="Event Customer:" HorizontalAlignment="Left" Height="43" Margin="7,202,0,0" VerticalAlignment="Top" Width="142" FontSize="16" FontFamily="Arial" FontWeight="Bold"/>
            <TextBox x:Name="TxtCust" HorizontalAlignment="Left" Height="33" Margin="342,22,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="200" ToolTip="Enter Event Number..." TextChanged="TxtCust_TextChanged" KeyDown="TxtCust_KeyDown"/>
            <CheckBox x:Name="ChkActive" Content="Active Events Only" IsChecked="True" HorizontalAlignment="Left" Height="19" Margin="13,238,0,0" VerticalAlignment="Top" Width="124" Checked="ChkActive_Checked" Unchecked="ChkActive_UnChecked"/>

            <Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="1" Margin="7,267,0,0" VerticalAlignment="Top" Width="524" Opacity="0.2" RenderTransformOrigin="0.5,0.5">
                <Border.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleY="-1"/>
                        <SkewTransform/>
                        <RotateTransform/>
                        <TranslateTransform/>
                    </TransformGroup>
                </Border.RenderTransform>
            </Border>

            <Button x:Name="BtnSearch" Click="BtnSearch_Click" HorizontalAlignment="Left" Width="100" Background="#FF333333" Foreground="White" FontWeight="Normal" FontSize="14" Margin="422,162,0,0" Height="37" VerticalAlignment="Top">
                <TextBlock Text="SEARCH" VerticalAlignment="Center" TextAlignment="Right" FontSize="14" Width="73" Height="15" FontFamily="Arial" Foreground="White" RenderTransformOrigin="0.684,0.261"/>
            </Button>

            <ListBox x:Name="LstEvents" HorizontalAlignment="Left" Margin="10,300,0,14" Width="524" BorderBrush="Black" BorderThickness="2,2,1,1">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Height="97">
                            <Canvas x:Name="EventItem" HorizontalAlignment="Left" Height="97" VerticalAlignment="Top" Width="502" Background="{Binding LBackground}" Margin="0,0,0,-21">
                                <Label Content="Event:" HorizontalAlignment="Left" Height="33" VerticalAlignment="Top" Width="97" FontWeight="Bold" FontSize="14" Canvas.Left="1" Canvas.Top="2"/>
                                <Label Content="Subject:" HorizontalAlignment="Left" Height="33" VerticalAlignment="Top" Width="97" FontWeight="Bold" FontSize="14" Canvas.Left="1" Canvas.Top="23"/>
                                <Label Content="Body:" HorizontalAlignment="Left" Height="33" VerticalAlignment="Top" Width="97" FontWeight="Bold" FontSize="14" Canvas.Left="1" Canvas.Top="47"/>
                                <Button x:Name="BtnSelectEvent" Content="Select" HorizontalAlignment="Left" Height="34" VerticalAlignment="Top" Width="74" Background="#FF333333" Foreground="White" FontWeight="Normal" FontSize="14" Canvas.Left="418" Canvas.Top="33" Click="BtnSelectEvent_Click"/>
                                <Label Content="{Binding Lsubject}" Height="25" Canvas.Left="80" Canvas.Top="3" Width="333"/>
                                <Label Content="{Binding Lbody}" Height="25" Canvas.Left="80" Canvas.Top="25" Width="333"/>
                                <Label Content="{Binding Lbody}" Height="25" Canvas.Left="80" Canvas.Top="49" Width="333"/>
                                <Label Content="Customer:" HorizontalAlignment="Left" Height="33" VerticalAlignment="Top" Width="97" FontWeight="Bold" FontSize="14" Canvas.Left="1" Canvas.Top="69"/>
                                <Label Content="{Binding LCust}" Height="25" Canvas.Left="80" Canvas.Top="71" Width="333"/>
                            </Canvas>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <Label x:Name="LblResultsReturned" Content="" HorizontalAlignment="Left" Height="27" Margin="37,273,0,-19" VerticalAlignment="Top" Width="492" FontWeight="Bold" FontFamily="Arial" FontSize="11" />
            <Label x:Name="LblEventCount" Content="" HorizontalAlignment="Left" Height="27" Margin="10,273,0,-19" VerticalAlignment="Top" FontWeight="Bold" FontFamily="Arial" FontSize="11" />
            <Image x:Name="ImgSearch" HorizontalAlignment="Left" Height="28" Margin="431,171,0,0" VerticalAlignment="Top" Width="22" Source="Images/Icon-Search-Big-White.png" RenderTransformOrigin="0.419,1.269"/>
            <Label x:Name="LblError" Content="" HorizontalAlignment="Left" Height="27" Margin="199,273,0,-19" VerticalAlignment="Top" Width="330" FontWeight="Bold" FontFamily="Arial" FontSize="11" />
            <Controls:ProgressRing x:Name="LoadingRing" IsActive="False" Margin="356,153,126,0" VerticalAlignment="Top"/>
        </Grid>
   </Border>
</Controls:MetroWindow>
4
  • 3
    Read the InnerException. Commented Jan 2, 2014 at 16:25
  • {"The type initializer for 'MahApps.Metro.Behaviours.StylizedBehaviors' threw an exception."} Commented Jan 2, 2014 at 16:30
  • Then there is a problem in the static constructor of StylizedBehaviors Commented Jan 2, 2014 at 16:35
  • 1
    Read the Inner InnerException. Commented Jan 2, 2014 at 16:46

4 Answers 4

2

Going on what you said in the comments it seems it is linked to the MahApps Metro Theme.

Take a look at this: https://github.com/MahApps/MahApps.Metro/issues/582

If you have referenced the Windows Interactivity dll try removing it.

In future remember to check the InnerException like SLaks said. You can learn a lot more from this and give you more to work on.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Removing it did work however some of my newer stuff has stopped working. I will take a deeper look into it.
2

Maybe for someone it will be useful. Today I ran into the same problem:

"XamlParseException on window initialization" in project with nuget reference to MahApp. I tryed reinstaling packages, removing references - nothithing helped.

In may case the problem was in app.config. When I removed these lines, problem disappeared:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Windows.Interactivity" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Does anyone know why this happens?

Comments

0

I think you just imported the wrong dll (NET40). Try to import the latest MahApps.Metro.dll (NET45).

It worked for me.

Comments

0

For me, I downgraded the MahApps.Metro to version 1.6.4 and the error has gone I was using version 1.6.5 before

And the version of MahApps.Metro.Resources is 0.6.1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.