title: NullReferenceException in Designer due to UserControl
body: <p>So I'm trying to make an application with 2 user controls side by side, that slide left and right when you switch between them. The problem is, that one of my user controls (AddReferencePage), when added to the MainWindow, causes the opening  tag on my MainWindow to become underlined with a NullReferenceException Error. The designer also shows an error:</p>
  
  <pre><code>NullReferenceException: Object reference not set to an instance of an object.
  
  StackTrace:
   at ARC.AddReferencePage.ReferenceDetails()
  at ARC.AddReferencePage.AddReferencePage_Loaded(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
  </code></pre>
  
  <p>The code to display my user controls is:</p>
  
  <pre><code>&lt;DockPanel x:Name="SlideGrid" VerticalAlignment="Stretch" Width="{Binding ActualWidth, ElementName=MainGrid, Converter={StaticResource DoubleConverter}}" Margin="0,28,0,0" ClipToBounds="True"&gt;
      &lt;ItemsControl DockPanel.Dock="Left"&gt;
          &lt;local:MainPage/&gt;
      &lt;/ItemsControl&gt;
      &lt;ItemsControl DockPanel.Dock="Right"&gt;
          &lt;local:AddReferencePage/&gt;
      &lt;/ItemsControl&gt;
  &lt;/DockPanel&gt;
  </code></pre>
  
  <p>The MainPage works fine, no errors what so ever. Its the AddReferencePage that causes the errors. I have checked through each of the user controls respective code behinds, and they are for all intents and purposes identical.</p>
  
  <p>Code behind for MainPage:</p>
  
  <pre><code>Imports System.Collections.ObjectModel
  Imports System.ComponentModel
  Imports System.Collections.Specialized
  Imports System.Windows.Threading
  Imports System.Windows.Media.Animation
  Imports System.Globalization
  
  Public Class MainPage
  Private StartPoint As Point
  
  Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
      'Dim PW As MainWindow = Window.GetWindow(MainPage)
      'If PW IsNot Nothing Then
      '    ReferenceList.ItemsSource = PW.ReferenceCollection
      '    Dim Alphabetical As SortDescription = New SortDescription("PropLastName", ListSortDirection.Ascending)
      '    ReferenceList.Items.SortDescriptions.Add(Alphabetical)
      'End If
      RefreshReferences()
  End Sub
  
  Public Sub RefreshReferences()
      Dim PW As MainWindow = Window.GetWindow(MainPage)
      If PW IsNot Nothing Then
          ReferenceList.ItemsSource = PW.ReferenceCollection
          Dim Alphabetical As SortDescription = New SortDescription("PropLastName", ListSortDirection.Ascending)
          ReferenceList.Items.SortDescriptions.Add(Alphabetical)
      End If
  End Sub
  
  Private Sub ListBoxSearch_TextChanged(sender As Object, e As TextChangedEventArgs) Handles ListBoxSearch.TextChanged
      If ListBoxSearch.Text &lt;&gt; "Search..." Then
          Dim PW As MainWindow = Window.GetWindow(MainPage)
          If PW IsNot Nothing Then
              PW.view = CollectionViewSource.GetDefaultView(PW.ReferenceCollection)
              PW.view.Filter = New Predicate(Of Object)(AddressOf PW.FilterList)
          End If
      End If
  
  End Sub
  
  Private Sub ListBoxSearch_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs) Handles ListBoxSearch.PreviewMouseDown
      If ListBoxSearch.Text = "Search..." Then
          ListBoxSearch.FontStyle = FontStyles.Normal
          ListBoxSearch.Clear()
      End If
  End Sub
  
  
  Private Sub ListBoxSearch_LostFocus(sender As Object, e As RoutedEventArgs) Handles ListBoxSearch.LostFocus
      If ListBoxSearch.Text = "" Then
          ListBoxSearch.FontStyle = FontStyles.Italic
          ListBoxSearch.Text = "Search..."
      End If
  End Sub
  
  Private Sub ListViewClick(sender As Object, e As RoutedEventArgs) Handles ButtonListView.Click
      If ReferenceList.ItemTemplate Is FindResource("GridViewTemplate") Then
          ViewBackground.BeginStoryboard(DirectCast(Me.Resources("ViewRightToLeft"), Storyboard))
          ReferenceList.ItemTemplate = DirectCast(Me.FindResource("ListViewTemplate"), DataTemplate)
          ButtonListView.Content = FindResource("NoListView")
          ButtonGridView.Content = FindResource("NoGridView")
      End If
  End Sub
  
  Private Sub GridViewClick(sender As Object, e As RoutedEventArgs) Handles ButtonGridView.Click
      If ReferenceList.ItemTemplate Is FindResource("ListViewTemplate") Then
          ViewBackground.BeginStoryboard(DirectCast(Me.Resources("ViewLeftToRight"), Storyboard))
          ReferenceList.ItemTemplate = DirectCast(Me.FindResource("GridViewTemplate"), DataTemplate)
          ButtonListView.Content = FindResource("NoListView")
          ButtonGridView.Content = FindResource("NoGridView")
      End If
  End Sub
  
  Private Sub ListViewEnter(sender As Object, e As RoutedEventArgs) Handles ButtonListView.MouseEnter
  
  End Sub
  
  Private Sub GridViewEnter(sender As Object, e As RoutedEventArgs) Handles ButtonGridView.MouseEnter
  
  End Sub
  
  Private Sub ListViewLeave(sender As Object, e As RoutedEventArgs) Handles ButtonListView.MouseLeave
  
  End Sub
  
  Private Sub GridViewLeave(sender As Object, e As RoutedEventArgs) Handles ButtonGridView.MouseLeave
  
  End Sub
  
  Private Sub EditListBoxItem(sender As Object, e As RoutedEventArgs)
      Dim PW As MainWindow = Window.GetWindow(MainPage)
      If PW IsNot Nothing Then
          PW.ChangeSlide(sender, 1)
          PW.EditItem = ReferenceList.SelectedItem
          PW.NewItem = False
      End If
  End Sub
  
  Private Sub DeleteListBoxItem(sender As Object, e As RoutedEventArgs)
      Dim PW As MainWindow = Window.GetWindow(MainPage)
      If PW IsNot Nothing Then
          PW.ReferenceCollection.Remove(ReferenceList.SelectedItem)
      End If
  End Sub
  
  Private Sub NewListBoxItem(sender As Object, e As RoutedEventArgs)
      Dim PW As MainWindow = Window.GetWindow(MainPage)
      If PW IsNot Nothing Then
          PW.ChangeSlide(sender, 1)
          PW.NewItem = True
      End If
  End Sub
  
  Private Sub ReferenceList_Loaded(sender As Object, e As RoutedEventArgs) Handles ReferenceList.Loaded
      RefreshReferences()
  End Sub
  
  Private Sub ReferenceList_PreviewMouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles ReferenceList.PreviewMouseLeftButtonDown
      Dim PW As MainWindow = Window.GetWindow(MainPage)
      StartPoint = e.GetPosition(Nothing)
      PW.Resizing = False
  End Sub
  
  Private Sub ReferenceList_PreviewMouseMove(sender As Object, e As MouseEventArgs) Handles ReferenceList.PreviewMouseMove
      Dim PW As MainWindow = Window.GetWindow(MainPage)
      If PW.Resizing = False Then
          Dim MousePosition As Point = e.GetPosition(Nothing)
          Dim Difference As Vector = StartPoint - MousePosition
          Dim StopDrop As Boolean
          If e.LeftButton = MouseButtonState.Pressed AndAlso (Math.Abs(Difference.X) &gt; SystemParameters.MinimumHorizontalDragDistance Or Math.Abs(Difference.Y) &gt; SystemParameters.MinimumVerticalDragDistance) Then
              Dim LB As ListBox = sender
              Dim UIE As UIElement = LB.InputHitTest(MousePosition)
              If UIE IsNot Nothing Then
                  Dim Data As Object = DependencyProperty.UnsetValue
                  While Data Is DependencyProperty.UnsetValue And UIE IsNot Nothing
                      Data = LB.ItemContainerGenerator.ItemFromContainer(UIE)
                      If Data Is DependencyProperty.UnsetValue Then
                          UIE = VisualTreeHelper.GetParent(UIE)
                      End If
                      If UIE Is LB Then
                          StopDrop = True
                      End If
                  End While
                  If Data IsNot DependencyProperty.UnsetValue Then
                      StopDrop = False
                  End If
              Else
                  StopDrop = True
              End If
              PW.TempItem = LB.SelectedItem
              Dim FN As String = PW.TempItem.PropLastName &amp; ", " &amp; PW.TempItem.PropFirstName.Substring(0, 1)
              Dim TT As String = PW.TempItem.PropTitle
              Dim YR As String = PW.TempItem.PropYear.ToString
              Dim ReferenceText As String = FN &amp; " " &amp; YR &amp; ", " &amp; TT
              Dim DragData As DataObject = New DataObject(DataFormats.StringFormat, ReferenceText)
              If DragData IsNot Nothing And StopDrop = False Then
                  DragDrop.DoDragDrop(sender, DragData, DragDropEffects.Copy)
              End If
          End If
      End If
  
  End Sub
  End Class
  </code></pre>
  
  <p>XAML for MainPage:</p>
  
  <pre><code>&lt;UserControl x:Class="MainPage" x:Name="MainPage"
           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:local="clr-namespace:ARC"
           mc:Ignorable="d"
           VerticalAlignment="Stretch" HorizontalAlignment="Stretch" d:DesignWidth="400" d:DesignHeight="600" SnapsToDevicePixels="True"&gt;
  &lt;UserControl.Resources&gt;
      &lt;local:ImageConverter x:Key="ImageConverter"/&gt;
      &lt;Image x:Key="BrownBook" Source="Images\Icons\BrownBook.png" Height="64" Width="64"/&gt;
  
      &lt;Storyboard x:Key="ViewRightToLeft" 
                  AccelerationRatio=".5"
                  DecelerationRatio=".5"&gt;
          &lt;ThicknessAnimation Storyboard.TargetName="ViewBackground" Storyboard.TargetProperty="Margin" Duration="0:0:0.15" To="0,0,28,0"/&gt;
      &lt;/Storyboard&gt;
  
      &lt;Storyboard x:Key="ViewLeftToRight" 
                  AccelerationRatio=".5"
                  DecelerationRatio=".5"&gt;
          &lt;ThicknessAnimation Storyboard.TargetName="ViewBackground" Storyboard.TargetProperty="Margin" Duration="0:0:0.15" To="0,0,-28,0"/&gt;
      &lt;/Storyboard&gt;
  &lt;/UserControl.Resources&gt;
  
  &lt;Grid Background="#FFF1F1F1"&gt;
      &lt;Grid&gt;
          &lt;DockPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch"&gt;
              &lt;DockPanel Margin="0,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="28" DockPanel.Dock="Top" Background="#E5E5E5"&gt;
                  &lt;Button BorderThickness="0" x:Name="AddNewReference" Style="{DynamicResource NoChromeButton}" DockPanel.Dock="Right" HorizontalAlignment="Right" Click="ListViewClick" Height="28" Width="28"&gt;
                      &lt;DynamicResource ResourceKey="SearchBar"/&gt;
                  &lt;/Button&gt;
                  &lt;Button BorderThickness="0" x:Name="Settings" Style="{DynamicResource NoChromeButton}" DockPanel.Dock="Right" HorizontalAlignment="Right" Click="ListViewClick" Height="28" Width="28"&gt;
                      &lt;DynamicResource ResourceKey="SearchBar"/&gt;
                  &lt;/Button&gt;
                  &lt;Grid Margin="0,0,0,0" DockPanel.Dock="Right" Width="56" Height="28" VerticalAlignment="Top" HorizontalAlignment="Stretch"&gt;
                      &lt;Button Height="28" Width="28" Margin="0,0,28,0" BorderThickness="0" Style="{DynamicResource NoChromeButton}" x:Name="ViewBackground" Background="#3E3B3B"/&gt;
                      &lt;Button Margin="0,0,0,0" BorderThickness="0" x:Name="ButtonGridView" Style="{DynamicResource NoChromeButton}" HorizontalAlignment="Right" Click="GridViewClick" Height="28" Width="28"&gt;
                          &lt;DynamicResource ResourceKey="NoGridView"/&gt;
                      &lt;/Button&gt;
                      &lt;Button Margin="0,0,28,0" BorderThickness="0" x:Name="ButtonListView" Style="{DynamicResource NoChromeButton}" HorizontalAlignment="Right" Click="ListViewClick" Height="28" Width="28"&gt;
                          &lt;DynamicResource ResourceKey="NoListView"/&gt;
                      &lt;/Button&gt;
  
                  &lt;/Grid&gt;
                  &lt;Button BorderThickness="0" x:Name="SearchBarIcon" Style="{DynamicResource NoChromeButton}" DockPanel.Dock="Left" HorizontalAlignment="Right" Click="ListViewClick" Height="28" Width="23"&gt;
                      &lt;DynamicResource ResourceKey="SearchBar"/&gt;
                  &lt;/Button&gt;
                  &lt;TextBox x:Name="ListBoxSearch" Style="{DynamicResource SearchBoxTemplate}" Text="Search..." FontSize="16" HorizontalAlignment="Stretch" FontStyle="Italic" BorderThickness="0" Foreground="Gray" Background="Transparent" VerticalContentAlignment="Top"/&gt;
  
              &lt;/DockPanel&gt;
              &lt;ListBox AlternationCount="2"  DockPanel.Dock="Top" Margin="0,0,0,0" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding ReferenceCollection, ElementName=local:MainWindow}" TextSearch.TextPath="SearchString" x:Name="ReferenceList" HorizontalContentAlignment="Stretch" ScrollViewer.CanContentScroll="False" SnapsToDevicePixels="True" AllowDrop="True" BorderThickness="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt;
                  &lt;ListBox.Background&gt;
                      &lt;LinearGradientBrush StartPoint="1,1" EndPoint="1,0"&gt;
                          &lt;GradientStop Offset="0.0" Color="#190000FF"/&gt;
                          &lt;GradientStop Color="#000000FF" Offset="1.0"/&gt;
                      &lt;/LinearGradientBrush&gt;
                  &lt;/ListBox.Background&gt;
                  &lt;ListBox.ItemTemplate&gt;
                          &lt;StaticResource ResourceKey="ListViewTemplate"/&gt;
                  &lt;/ListBox.ItemTemplate&gt;
                  &lt;ListBox.ContextMenu&gt;
                      &lt;ContextMenu Style="{StaticResource ListBoxContextMenu}"&gt;
                          &lt;MenuItem x:Name="EditContextMenuItem" Header="Edit" Click="EditListBoxItem" Style="{StaticResource ListBoxContextMenuItem}"/&gt;
                          &lt;MenuItem x:Name="DeleteContextMenuItem" Header="Delete" Click="DeleteListBoxItem" Style="{StaticResource ListBoxContextMenuItem}"/&gt;
                          &lt;MenuItem x:Name="NewContextMenuItem" Header="New" Click="NewListBoxItem" Style="{StaticResource ListBoxContextMenuItem}"/&gt;
                      &lt;/ContextMenu&gt;
                  &lt;/ListBox.ContextMenu&gt;
              &lt;/ListBox&gt;
          &lt;/DockPanel&gt;
      &lt;/Grid&gt;
  &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Code behind for AddReferencePage:</p>
  
  <pre><code>Imports System.Collections.ObjectModel
  Imports System.ComponentModel
  Imports System.Collections.Specialized
  Imports System.Windows.Threading
  Imports System.Windows.Media.Animation
  Imports System.Globalization
  
  Public Class AddReferencePage
  Private SelectImage As Boolean = False
  
  Private Sub ReturnToReferences(sender As Object, e As RoutedEventArgs)
      Dim PW As MainWindow = Window.GetWindow(AddReferencePage)
      If PW IsNot Nothing Then
          If ReferenceAuthor.Text &lt;&gt; "Author" Or ReferenceDate.Text &lt;&gt; "Date" Or ReferenceTitle.Text &lt;&gt; "Title" Then
              Dim CN As String() = Nothing
              Dim FN As String = Nothing
              Dim LN As String = Nothing
              Dim YR As String = Nothing
              Dim TT As String = Nothing
  
              If ReferenceAuthor.Text = "Author" Then
                  ReferenceAuthor.Text = "Unknown"
                  FN = Nothing
                  LN = "Unknown"
              Else
                  If ReferenceAuthor.Text.Contains(" ") Then
                      CN = ReferenceAuthor.Text.Split(" ")
                      FN = CN.First
                      LN = CN.Last
                  Else
                      FN = Nothing
                      LN = ReferenceAuthor.Text
                  End If
  
              End If
              If ReferenceDate.Text = "Date" Then
                  ReferenceDate.Text = "Unknown"
                  YR = "Unknown"
              Else
                  YR = ReferenceDate.Text
              End If
              If ReferenceTitle.Text = "Title" Then
                  ReferenceTitle.Text = "Unknown"
                  TT = "Unknown"
              Else
                  TT = ReferenceTitle.Text
              End If
              If PW.NewItem = False Then
                  PW.ReferenceCollection.Remove(PW.EditItem)
                  PW.AddReferenceItem(FN, LN, TT, YR, "Book")
              Else
                  PW.AddReferenceItem(FN, LN, TT, YR, "Book")
              End If
          End If
      End If
      PW.ChangeSlide(sender, 0)
  End Sub
  
  Private Sub ButtonsMouseEnter(sender As Button, e As RoutedEventArgs)
      Select Case sender.Name
          Case "ReturnReferences"
              sender.Content = FindResource("BackArrowHover")
      End Select
  End Sub
  
  Private Sub ButtonsMouseLeave(sender As Button, e As RoutedEventArgs)
      Select Case sender.Name
          Case "ReturnReferences"
              sender.Content = FindResource("BackArrowNormal")
      End Select
  End Sub
  
  Private Sub ButtonsMouseDown(sender As Button, e As RoutedEventArgs)
      Select Case sender.Name
          Case "ReturnReferences"
              sender.Content = FindResource("BackArrowClick")
      End Select
  End Sub
  
  Public Sub SaveReferenceSub(sender As Object, e As RoutedEventArgs)
      Dim PW As MainWindow = Window.GetWindow(AddReferencePage)
      Dim CN As String() = ReferenceAuthor.Text.Split(" ")
      Dim FN As String = CN.First()
      Dim LN As String = CN.Last()
      Dim YR As Integer = CInt(ReferenceDate.Text)
      Dim TT As String = ReferenceTitle.Text
      If PW.NewItem = False Then
          PW.ReferenceCollection.Remove(PW.EditItem)
          PW.AddReferenceItem(FN, LN, TT, YR, "Book")
      Else
          PW.AddReferenceItem(FN, LN, TT, YR, "Book")
      End If
  End Sub
  
  Private Sub ReferenceDetails()
      Dim PW As MainWindow = Window.GetWindow(AddReferencePage)
      If PW.NewItem = False Then
          ReferenceAuthor.Text = PW.EditItem.PropFirstName &amp; " " &amp; PW.EditItem.PropLastName
          ReferenceTitle.Text = PW.EditItem.PropTitle
          ReferenceDate.Text = PW.EditItem.PropYear.ToString
      End If
  End Sub
  
  Private Sub AddReferencePage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
      ReferenceDetails()
  End Sub
  
  Private Sub FieldEnter(sender As TextBox, e As RoutedEventArgs)
      Select Case sender.Name
          Case "ReferenceAuthor"
              If sender.Text = "Author" Then
                  sender.Clear()
              End If
          Case "ReferenceTitle"
              If sender.Text = "Title" Then
                  sender.Clear()
              End If
          Case "ReferenceDate"
              If sender.Text = "Date" Then
                  sender.Clear()
              End If
      End Select
  End Sub
  
  Private Sub FieldLeave(sender As TextBox, e As RoutedEventArgs)
      If sender.Text = "" Then
          Select Case sender.Name
              Case "ReferenceAuthor"
                  sender.Text = "Author"
              Case "ReferenceTitle"
                  sender.Text = "Title"
              Case "ReferenceDate"
                  sender.Text = "Date"
          End Select
      End If
  End Sub
  
  Private Sub FieldChanged(sender As TextBox, e As RoutedEventArgs)
      If sender.Text &lt;&gt; "Author" And sender.Text &lt;&gt; "Date" And sender.Text &lt;&gt; "Title" Then
          sender.Foreground = Brushes.Black
      Else
          sender.Foreground = Brushes.Gray
      End If
  End Sub
  
  Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
      If SelectImage = False Then
          SelectImageBox.BeginStoryboard(DirectCast(Me.Resources("LeftToRight"), Storyboard))
          SelectImage = True
      Else
          SelectImageBox.BeginStoryboard(DirectCast(Me.Resources("RightToLeft"), Storyboard))
          SelectImage = False
      End If
  End Sub
  
  Private Sub SelectImageBox_LostFocus(sender As Object, e As RoutedEventArgs) Handles SelectImageBox.LostFocus
      'If SelectImage = True Then
      '    SelectImageBox.BeginStoryboard(DirectCast(Me.Resources("RightToLeft"), Storyboard))
      '    SelectImage = False
      'End If
  End Sub
  End Class
  </code></pre>
  
  <p>XAML for AddReferencePage:</p>
  
  <pre><code>&lt;UserControl x:Class="AddReferencePage" x:Name="AddReferencePage"
           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:local="clr-namespace:ARC"
           mc:Ignorable="d"
           VerticalAlignment="Stretch" SnapsToDevicePixels="True" HorizontalAlignment="Stretch" d:DesignWidth="400" d:DesignHeight="600"&gt;
  &lt;UserControl.Resources&gt;
      &lt;Storyboard x:Key="RightToLeft" 
                  AccelerationRatio=".5"
                  DecelerationRatio=".5"&gt;
          &lt;DoubleAnimation Storyboard.TargetName="ReferenceInfo" Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:0.3" To="0"/&gt;
          &lt;DoubleAnimation Storyboard.TargetName="SelectImageBox" Storyboard.TargetProperty="Opacity" Duration="0:0:0.3" From="1.0" To="0.0"/&gt;
      &lt;/Storyboard&gt;
  
      &lt;Storyboard x:Key="LeftToRight" 
                  AccelerationRatio=".5"
                  DecelerationRatio=".5"&gt;
          &lt;DoubleAnimation Storyboard.TargetName="ReferenceInfo" Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:0.3" To="{Binding ActualWidth, ElementName=AnimInfo}"/&gt;
          &lt;DoubleAnimation Storyboard.TargetName="SelectImageBox" Storyboard.TargetProperty="Opacity" Duration="0:0:0.3" From="0.0" To="1.0"/&gt;
      &lt;/Storyboard&gt;
  &lt;/UserControl.Resources&gt;
  
  
  &lt;Grid Background="#FFF1F1F1"&gt;
      &lt;Button Style="{DynamicResource NoChromeButton}" x:Name="ReturnReferences" Click="ReturnToReferences" MouseDown="ButtonsMouseDown" MouseEnter="ButtonsMouseEnter" MouseLeave="ButtonsMouseLeave" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5,5,0,0" Height="48" Width="48"&gt;
          &lt;DynamicResource ResourceKey="BackArrowNormal"/&gt;
      &lt;/Button&gt;
  
      &lt;TextBlock Text="Edit References" FontFamily="Segoe UI Light" FontSize="36" Margin="72,3,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch"/&gt;
      &lt;TextBlock x:Name="AnimInfo" FontFamily="Segoe UI Light" FontSize="36" Margin="72,3,60,0" VerticalAlignment="Top" HorizontalAlignment="Stretch"/&gt;
      &lt;ListView x:Name="SelectImageBox" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="72,59,60,20" Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderThickness="0" Opacity="0"&gt;
          &lt;ListView.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;WrapPanel Orientation="Horizontal" IsItemsHost="True"/&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ListView.ItemsPanel&gt;
          &lt;Button Style="{DynamicResource NoChromeButton}" Height="48" Width="48"&gt;
              &lt;DynamicResource ResourceKey="Book"/&gt;
          &lt;/Button&gt;
          &lt;Button Style="{DynamicResource NoChromeButton}" Height="48" Width="48"&gt;
              &lt;DynamicResource ResourceKey="Book"/&gt;
          &lt;/Button&gt;
          &lt;Button Style="{DynamicResource NoChromeButton}" Height="48" Width="48"&gt;
              &lt;DynamicResource ResourceKey="Book"/&gt;
          &lt;/Button&gt;
          &lt;Button Style="{DynamicResource NoChromeButton}" Height="48" Width="48"&gt;
              &lt;DynamicResource ResourceKey="Book"/&gt;
          &lt;/Button&gt;
          &lt;Button Style="{DynamicResource NoChromeButton}" Height="48" Width="48"&gt;
              &lt;DynamicResource ResourceKey="Book"/&gt;
          &lt;/Button&gt;
          &lt;Button Style="{DynamicResource NoChromeButton}" Height="48" Width="48"&gt;
              &lt;DynamicResource ResourceKey="Book"/&gt;
          &lt;/Button&gt;
      &lt;/ListView&gt;
      &lt;Canvas x:Name="InfoCanvas" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="72,60,0,0" Opacity="1"&gt;
          &lt;DockPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="ReferenceInfo" Canvas.Left="0" Canvas.Top="0" Width="{Binding ActualWidth, ElementName=InfoCanvas}" Height="{Binding ActualHeight, ElementName=InfoCanvas}"&gt;
              &lt;TextBox x:Name="ReferenceAuthor" GotFocus="FieldEnter" TextChanged="FieldChanged" LostFocus="FieldLeave" FontSize="16" FontFamily="Segoe UI Light" Text="Author" Foreground="Gray" Background="Transparent" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Stretch" BorderThickness="0" Margin="0,2,0,2"/&gt;
              &lt;TextBox x:Name="ReferenceTitle" GotFocus="FieldEnter" TextChanged="FieldChanged" LostFocus="FieldLeave" FontSize="16" FontFamily="Segoe UI Light" Text="Title" Foreground="Gray" Background="Transparent" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Stretch" BorderThickness="0" Margin="0,2,0,2"/&gt;
              &lt;TextBox x:Name="ReferenceDate" GotFocus="FieldEnter" TextChanged="FieldChanged" LostFocus="FieldLeave" FontSize="16" FontFamily="Segoe UI Light" Text="Date" Foreground="Gray" Background="Transparent" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Stretch" BorderThickness="0" Margin="0,2,0,2"/&gt;
          &lt;/DockPanel&gt;
      &lt;/Canvas&gt;
      &lt;Button Style="{DynamicResource NoChromeButton}" Margin="5,60,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="48" Height="48" VerticalContentAlignment="Center" Click="Button_Click_1"&gt;
          &lt;DynamicResource ResourceKey="Book"/&gt;
      &lt;/Button&gt;
  &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>I know its a lot of code :D but I really need to fix this problem! Thanks all! Let me know if you need more details. All my resources and templates are defined in Application.xaml which I have not included, due to the irrelevance. I can include if needed.</p>