title: Color the textbox of a datepicker backend WPF
body: <p>I would like to change the color of the border datepicker , I saw solutions for changing in the xaml code, but would like to change it backend.</p>
  
  <p>my code:</p>
  
  <pre><code>public static bool checkDate(DatePicker dpk)
  {
     TextBox tb = (TextBox)dpk.Template.FindName("PART_TextBox", dpk);
     Border bd = (Border)tb.Template.FindName("Bd", tb);
  
     if (dpk.SelectedDate == null)
     {
         bd.BorderBrush = Brushes.Red;
         return false;
     }
  
     bd.BorderBrush = Brushes.Black;
     return true;
  }
  </code></pre>
  
  <p>I have no problems using</p>
  
  <pre><code>Border bd = (Border)tb.Template.FindName("Bd", tb);
  </code></pre>
  
  <p>for my other textbox etc.. But I am getting a nullException error when coloring, apparently it could not detect the border of the textbox used by the datepicker at this paricular line of code. Any advice?</p>