private void CardChangedHandler(object sender, DependencyPropertyChangedEventArgs e)
{
if (Card != null)
Card.PropertyChanged -= PropertyChangeHandler;
Card = DataContext as Card;
if (Card == null) return;
bool oldIsUp = IsUp;
IsUp = IsAlwaysUp || Card.FaceUp;
// If IsUp changes, it automatically updates the picture.
// Otherwise do it explicitely
if (oldIsUp == IsUp)
SetDisplayedPicture(Card.GetBitmapImage(IsUp));
//SetDisplayedPicture(Card.GetPicture(IsUp));
IsAnchored = Card.Anchored;
UpdateInvertedTransform();
Card.PropertyChanged += PropertyChangeHandler;
//InvalidateMeasure();
InvalidateVisual();
OnPropertyChanged("ActualWidth");
OnPropertyChanged("ActualHeight");
AnimateOrientation(Card.Orientation);
}