void ShowSearch_OnClick(object sender, RoutedEventArgs e) { DoubleAnimation animation; if (_searchIsOpen) { animation = new DoubleAnimation(SearchClosedLeft, _searchDuration); } else { animation = new DoubleAnimation(SearchOpenLeft, _searchDuration); } _searchIsOpen = !_searchIsOpen; SearchGrid.BeginAnimation(Canvas.LeftProperty, animation); }