title: Where to set window property in XAML
body: <p>I found some code for an attached property that will let me escape close a window called as a dialog <a href="https://stackoverflow.com/questions/419596/how-does-the-wpf-button-iscancel-property-work">here on SO</a>.</p>
  
  <p>But I can't figure out where to set the property.</p>
  
  <p>This might be complicated by the fact that this is a RibbonWindow and not a normal Window but I don't think so. </p>
  
  <p>The attached property will be ab:WindowService.EscapeClosesWindow="True". Where in the xaml should it go??</p>
  
  <p>Cheers,<br>
  Berryl</p>
  
  <h1>ERROR</h1>
  
  <pre><code>Unable to cast object of type 
  'Microsoft.Expression.Platform.WPF.InstanceBuilders.WindowInstance' to type 
  'Microsoft.Windows.Controls.Ribbon.RibbonWindow'.
  at  AttachedBehaviors.WindowService.OnEscapeClosesWindowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
  </code></pre>
  
  <h1>The gist of the attached property is</h1>
  
  <pre><code>    private static void OnEscapeClosesWindowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
          var target = (Window) d;
          if (target != null) 
              target.PreviewKeyDown += Window_PreviewKeyDown;
      }
  
      /// &lt;summary&gt;Handle the PreviewKeyDown event on the window&lt;/summary&gt;
      private static void Window_PreviewKeyDown(object sender, KeyEventArgs e) {
          var target = (Window) sender;
  
          // If this is the escape key, close the window
          if (e.Key == Key.Escape)
              target.Close();
      }
  </code></pre>
  
  <h1>window xaml</h1>
  
  <pre><code>&lt;r:RibbonWindow x:Class="SCA.Presentation.Wpf.Views.TimeSheet.WeeklyTimeSheetView"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local ="clr-namespace:SCA.Presentation.Wpf.Views.TimeSheet" 
  xmlns:ab="clr-namespace:SCA.Presentation.Wpf.AttachedBehaviors;assembly=Smack.Core.Presentation.Wpf"
  xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary" 
     Background="{DynamicResource WaveWindowBackground}"
     FontFamily="Arial" FontSize="12" 
     Width="900" Height="600"
     ResizeMode="CanResizeWithGrip"
     WindowStartupLocation="CenterScreen"
               ab:WindowService.EscapeClosesWindow="True" &lt;=== ERROR
  
      &gt;
  
  &lt;r:RibbonWindow.Resources&gt;
      &lt;ResourceDictionary Source="TimesheetResources.xaml" /&gt;
  &lt;/r:RibbonWindow.Resources&gt;
  </code></pre>