title: UWP: Adjusting InkCanvas size when writing/drawing
body: <p>I'm learning how to develop UWP apps and I'm using Microsoft's documentation as tutorials/research.</p>
  <p>I want to have an InkCanvas design similar to OneNote where the InkCanvas height and width can expand (as you're writing/drawing and reach the end of the window size) and can shrink (when you erase ink strokes and the extra size can decrease based on the position of the ink strokes until you get back to the original size).</p>
  <p>I'm able to increase the InkCanvas width and height, but can't decrease when erasing ink strokes.</p>
  <p>Here is a MainPage.xaml code:</p>
  <pre><code>&lt;Grid&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width=&quot;*&quot; /&gt;
          &lt;ColumnDefinition Width=&quot;*&quot; /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
  
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height=&quot;Auto&quot; /&gt;
          &lt;RowDefinition Height=&quot;*&quot; /&gt;
      &lt;/Grid.RowDefinitions&gt;
  
      &lt;TextBlock Text=&quot;Heading&quot;
                     FontSize=&quot;36&quot;
                     FontWeight=&quot;Bold&quot;
                     Margin=&quot;10&quot;
                     Grid.Column=&quot;0&quot;
                     Grid.Row=&quot;0&quot;/&gt;
  
      &lt;Grid BorderBrush=&quot;Red&quot;
                      BorderThickness=&quot;2&quot;
                      Margin=&quot;10&quot;
                      Grid.Column=&quot;0&quot;
                      Grid.Row=&quot;1&quot;&gt;
          &lt;ScrollViewer HorizontalScrollBarVisibility=&quot;Auto&quot;
                        HorizontalScrollMode=&quot;Enabled&quot;
                        VerticalScrollBarVisibility=&quot;Auto&quot;
                        VerticalScrollMode=&quot;Enabled&quot; &gt;
  
              &lt;Grid BorderBrush=&quot;Blue&quot;
                      BorderThickness=&quot;2&quot;
                      Margin=&quot;1&quot;&gt;
                  &lt;InkCanvas Name=&quot;inkCanvas&quot;/&gt;
              &lt;/Grid&gt;
          &lt;/ScrollViewer&gt;
  
      &lt;/Grid&gt;
  </code></pre>
  <p>And the MainPage.cs code:</p>
  <pre><code>public MainPage()
      {
          this.InitializeComponent();
          nkCanvas.InkPresenter.StrokeInput.StrokeEnded += adjustInkCanvasSize;
      }
  
      private  async void adjustInkCanvasSize(InkStrokeInput sender, PointerEventArgs args)
      {
          await Task.Delay(100);
  
          var XBound = inkCanvas.InkPresenter.StrokeContainer.BoundingRect.Bottom;
          if (XBound &gt; inkCanvas.ActualHeight - 200)
              inkCanvas.Height = XBound + 200;
  
          var YBound = inkCanvas.InkPresenter.StrokeContainer.BoundingRect.Right;
          if (YBound &gt; inkCanvas.ActualWidth - 200)
              inkCanvas.Width = YBound + 200;
       }
  </code></pre>
  <p>The c# code also came from another stackoverflow solution, but not able to figure out the &quot;decrease&quot; part.</p>
  <p>Any help would be much appreciated. Thanks</p>