private void _Player_PileChanged(object sender, PileChangedEventArgs e)
		{
			if (this.Dispatcher.CheckAccess())
			{

				// This sometimes has an Enumeration exception -- can't figure out how to Lock it properly
				if (e.Player != null)
					try { lVictoryPoints.Content = e.Player.VictoryPoints.ToString(); }
					catch { lVictoryPoints.Content = "0"; }

				Deck deck = sender as Deck;
				Boolean visible = this.IsUIPlayer || (e.Player != null && e.Player.Phase == DominionBase.Players.PhaseEnum.Endgame);

				switch (deck.DeckLocation)
				{
					case DeckLocation.Hand:
						cardHand.ExactCount = true;
						cardHand.IsCardsVisible = visible;
						cardHand.Phase = e.Player.Phase;
						cardHand.PlayerMode = e.Player.PlayerMode;
						cardHand.CardSize = e.Player.Phase == PhaseEnum.Endgame ? CardSize.Text : CardSize.Medium;
						cardHand.IsVPsVisible = e.Player.Phase == PhaseEnum.Endgame ? true : false;
						cardHand.Pile = deck;
						if (visible)
							svPlayerDisplay.ScrollToTop();
						break;

					case DeckLocation.Revealed:
						cardRevealed.ExactCount = true;
						cardRevealed.IsCardsVisible = true;
						cardRevealed.Phase = PhaseEnum.Action;
						cardRevealed.PlayerMode = PlayerMode.Waiting;
						cardRevealed.CardSize = CardSize.Small;
						if (e.Player.Revealed.Count > 0)
							bInPlayRevealedDivider.Visibility = cardRevealed.Visibility = System.Windows.Visibility.Visible;
						else
							bInPlayRevealedDivider.Visibility = cardRevealed.Visibility = System.Windows.Visibility.Collapsed;
						cardRevealed.Pile = deck;
						break;

					case DeckLocation.InPlay:
						cardInPlay.ExactCount = true;
						cardInPlay.IsCardsVisible = true;
						cardInPlay.Phase = PhaseEnum.Action;
						cardInPlay.PlayerMode = PlayerMode.Waiting;
						cardInPlay.CardSize = CardSize.Small;
						cardInPlay.Pile = deck;
						if (e.Player.PlayerUniqueId != _Player.UniqueId && e.Player.Phase != DominionBase.Players.PhaseEnum.Endgame)
							svPlayerDisplay.ScrollToVerticalOffset(cardHand.ActualHeight + cardDiscard.ActualHeight);

						break;

					case DeckLocation.SetAside:
						cardSetAside.ExactCount = true;
						cardSetAside.IsCardsVisible = true;
						cardSetAside.Phase = PhaseEnum.Action;
						cardSetAside.PlayerMode = PlayerMode.Waiting;
						cardSetAside.CardSize = CardSize.Small;
						if (deck.Count > 0)
							bSetAsideDivider.Visibility = cardSetAside.Visibility = System.Windows.Visibility.Visible;
						else
							bSetAsideDivider.Visibility = cardSetAside.Visibility = System.Windows.Visibility.Collapsed;
						cardSetAside.Pile = deck;

						break;

					case DeckLocation.Deck:
						cardDeck.ExactCount = this.IsUIPlayer;
						cardDeck.IsCardsVisible = false;
						cardDeck.Phase = PhaseEnum.Action;
						cardDeck.PlayerMode = PlayerMode.Waiting;
						cardDeck.CardSize = CardSize.Small;
						cardDeck.Pile = deck;
						break;

					case DeckLocation.Discard:
						cardDiscard.ExactCount = false;
						cardDiscard.IsCardsVisible = true;
						cardDiscard.Phase = PhaseEnum.Action;
						cardDiscard.PlayerMode = PlayerMode.Waiting;
						cardDiscard.CardSize = CardSize.Small;
						if (e.Player.DiscardPile.Count > 0)
							bDeckDiscardDivider.Visibility = cardDiscard.Visibility = System.Windows.Visibility.Visible;
						else
							bDeckDiscardDivider.Visibility = cardDiscard.Visibility = System.Windows.Visibility.Collapsed;
						cardDiscard.Pile = deck;
						break;

					case DeckLocation.Private:
						cardPrivate.ExactCount = true;
						cardPrivate.IsCardsVisible = visible;
						cardPrivate.Phase = PhaseEnum.Action;
						cardPrivate.PlayerMode = PlayerMode.Waiting;
						cardPrivate.CardSize = CardSize.Small;
						if (e.Player.Private.Count > 0)
							bRevealedLookingAtDivider.Visibility = cardPrivate.Visibility = System.Windows.Visibility.Visible;
						else
							bRevealedLookingAtDivider.Visibility = cardPrivate.Visibility = System.Windows.Visibility.Collapsed;
						cardPrivate.Pile = deck;
						break;

					case DeckLocation.PlayerMat:

						if (sender.GetType() == DominionBase.Cards.Seaside.TypeClass.IslandMat)
						{
							CardCollectionControl cccIsland = dpMatsandPiles.Children.OfType<CardCollectionControl>().SingleOrDefault(ccc => ccc.Name == "cardIsland");
							if (cccIsland == null)
							{
								if (dpMatsandPiles.Children.Count > 0)
								{
									Border bDiv = new Border();
									bDiv.BorderThickness = new Thickness(2);
									bDiv.BorderBrush = Brushes.Black;
									DockPanel.SetDock(bDiv, Dock.Left);
									dpMatsandPiles.Children.Add(bDiv);
								}
								cccIsland = new CardCollectionControl();
								cccIsland.Name = "cardIsland";
								cccIsland.Padding = new Thickness(0);
								DockPanel.SetDock(cccIsland, Dock.Left);
								//cccIsland.Background = Brushes.AliceBlue;
								cccIsland.PileName = "Island Mat";
								cccIsland.CardSize = CardSize.Text;
								dpMatsandPiles.Children.Add(cccIsland);
							}
							cccIsland.ExactCount = true;
							cccIsland.IsCardsVisible = true;
							cccIsland.Phase = PhaseEnum.Action;
							cccIsland.PlayerMode = PlayerMode.Waiting;
							cccIsland.Pile = deck;
						}
						else if (sender.GetType() == DominionBase.Cards.Seaside.TypeClass.NativeVillageMat)
						{
							CardCollectionControl cccNativeVillage = dpMatsandPiles.Children.OfType<CardCollectionControl>().SingleOrDefault(ccc => ccc.Name == "cardNativeVillage");
							if (cccNativeVillage == null)
							{
								if (dpMatsandPiles.Children.Count > 0)
								{
									Border bDiv = new Border();
									bDiv.BorderThickness = new Thickness(2);
									bDiv.BorderBrush = Brushes.Black;
									DockPanel.SetDock(bDiv, Dock.Left);
									dpMatsandPiles.Children.Add(bDiv);
								}
								cccNativeVillage = new CardCollectionControl();
								cccNativeVillage.Name = "cardNativeVillage";
								cccNativeVillage.Padding = new Thickness(0);
								DockPanel.SetDock(cccNativeVillage, Dock.Left);
								//cccNativeVillage.Background = Brushes.AliceBlue;
								cccNativeVillage.PileName = "Native Village Mat";
								cccNativeVillage.CardSize = CardSize.Text;
								dpMatsandPiles.Children.Add(cccNativeVillage);
							}
							cccNativeVillage.ExactCount = true;
							cccNativeVillage.IsCardsVisible = visible;
							cccNativeVillage.Phase = PhaseEnum.Action;
							cccNativeVillage.PlayerMode = PlayerMode.Waiting;
							cccNativeVillage.Pile = deck;
						}
						else if (sender.GetType() == DominionBase.Cards.Promotional.TypeClass.PrinceSetAside)
						{
							CardCollectionControl cccPrinceSetAside = dpMatsandPiles.Children.OfType<CardCollectionControl>().SingleOrDefault(ccc => ccc.Name == "cardPrinceSetAside");
							if (cccPrinceSetAside == null)
							{
								if (dpMatsandPiles.Children.Count > 0)
								{
									Border bDiv = new Border();
									bDiv.BorderThickness = new Thickness(2);
									bDiv.BorderBrush = Brushes.Black;
									DockPanel.SetDock(bDiv, Dock.Left);
									dpMatsandPiles.Children.Add(bDiv);
								}
								cccPrinceSetAside = new CardCollectionControl();
								cccPrinceSetAside.Name = "cardPrinceSetAside";
								cccPrinceSetAside.Padding = new Thickness(0);
								DockPanel.SetDock(cccPrinceSetAside, Dock.Left);
								cccPrinceSetAside.PileName = "Set Aside";
								cccPrinceSetAside.CardSize = CardSize.Text;
								dpMatsandPiles.Children.Add(cccPrinceSetAside);
							}
							cccPrinceSetAside.ExactCount = true;
							cccPrinceSetAside.IsCardsVisible = true;
							cccPrinceSetAside.CardSize = CardSize.Small;
							cccPrinceSetAside.Phase = PhaseEnum.Action;
							cccPrinceSetAside.PlayerMode = PlayerMode.Waiting;
							cccPrinceSetAside.Pile = deck;
						}

						break;
				}
			}
			else
			{
				this.Dispatcher.BeginInvoke(new EventHandler<PileChangedEventArgs>(_Player_PileChanged), System.Windows.Threading.DispatcherPriority.Normal, sender, e);
			}
		}
        private void _Player_PileChanged(object sender, PileChangedEventArgs e)
        {
            if (this.Dispatcher.CheckAccess())
            {
                // This sometimes has an Enumeration exception -- can't figure out how to Lock it properly
                if (e.Player != null)
                {
                    try { lVictoryPoints.Content = e.Player.VictoryPoints.ToString(); }
                    catch { lVictoryPoints.Content = "0"; }
                }

                Deck    deck    = sender as Deck;
                Boolean visible = this.IsUIPlayer || (e.Player != null && e.Player.Phase == DominionBase.Players.PhaseEnum.Endgame);

                switch (deck.DeckLocation)
                {
                case DeckLocation.Hand:
                    cardHand.ExactCount     = true;
                    cardHand.IsCardsVisible = visible;
                    cardHand.Phase          = e.Player.Phase;
                    cardHand.PlayerMode     = e.Player.PlayerMode;
                    cardHand.CardSize       = e.Player.Phase == PhaseEnum.Endgame ? CardSize.Text : CardSize.Medium;
                    cardHand.IsVPsVisible   = e.Player.Phase == PhaseEnum.Endgame ? true : false;
                    cardHand.Pile           = deck;
                    if (visible)
                    {
                        svPlayerDisplay.ScrollToTop();
                    }
                    break;

                case DeckLocation.Revealed:
                    cardRevealed.ExactCount     = true;
                    cardRevealed.IsCardsVisible = true;
                    cardRevealed.Phase          = PhaseEnum.Action;
                    cardRevealed.PlayerMode     = PlayerMode.Waiting;
                    cardRevealed.CardSize       = CardSize.Small;
                    if (e.Player.Revealed.Count > 0)
                    {
                        bInPlayRevealedDivider.Visibility = cardRevealed.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        bInPlayRevealedDivider.Visibility = cardRevealed.Visibility = System.Windows.Visibility.Collapsed;
                    }
                    cardRevealed.Pile = deck;
                    break;

                case DeckLocation.InPlay:
                    cardInPlay.ExactCount     = true;
                    cardInPlay.IsCardsVisible = true;
                    cardInPlay.Phase          = PhaseEnum.Action;
                    cardInPlay.PlayerMode     = PlayerMode.Waiting;
                    cardInPlay.CardSize       = CardSize.Small;
                    cardInPlay.Pile           = deck;
                    if (e.Player.PlayerUniqueId != _Player.UniqueId && e.Player.Phase != DominionBase.Players.PhaseEnum.Endgame)
                    {
                        svPlayerDisplay.ScrollToVerticalOffset(cardHand.ActualHeight + cardDiscard.ActualHeight);
                    }

                    break;

                case DeckLocation.SetAside:
                    cardSetAside.ExactCount     = true;
                    cardSetAside.IsCardsVisible = true;
                    cardSetAside.Phase          = PhaseEnum.Action;
                    cardSetAside.PlayerMode     = PlayerMode.Waiting;
                    cardSetAside.CardSize       = CardSize.Small;
                    if (deck.Count > 0)
                    {
                        bSetAsideDivider.Visibility = cardSetAside.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        bSetAsideDivider.Visibility = cardSetAside.Visibility = System.Windows.Visibility.Collapsed;
                    }
                    cardSetAside.Pile = deck;

                    break;

                case DeckLocation.Deck:
                    cardDeck.ExactCount     = this.IsUIPlayer;
                    cardDeck.IsCardsVisible = false;
                    cardDeck.Phase          = PhaseEnum.Action;
                    cardDeck.PlayerMode     = PlayerMode.Waiting;
                    cardDeck.CardSize       = CardSize.Small;
                    cardDeck.Pile           = deck;
                    break;

                case DeckLocation.Discard:
                    cardDiscard.ExactCount     = false;
                    cardDiscard.IsCardsVisible = true;
                    cardDiscard.Phase          = PhaseEnum.Action;
                    cardDiscard.PlayerMode     = PlayerMode.Waiting;
                    cardDiscard.CardSize       = CardSize.Small;
                    if (e.Player.DiscardPile.Count > 0)
                    {
                        bDeckDiscardDivider.Visibility = cardDiscard.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        bDeckDiscardDivider.Visibility = cardDiscard.Visibility = System.Windows.Visibility.Collapsed;
                    }
                    cardDiscard.Pile = deck;
                    break;

                case DeckLocation.Private:
                    cardPrivate.ExactCount     = true;
                    cardPrivate.IsCardsVisible = visible;
                    cardPrivate.Phase          = PhaseEnum.Action;
                    cardPrivate.PlayerMode     = PlayerMode.Waiting;
                    cardPrivate.CardSize       = CardSize.Small;
                    if (e.Player.Private.Count > 0)
                    {
                        bRevealedLookingAtDivider.Visibility = cardPrivate.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        bRevealedLookingAtDivider.Visibility = cardPrivate.Visibility = System.Windows.Visibility.Collapsed;
                    }
                    cardPrivate.Pile = deck;
                    break;

                case DeckLocation.PlayerMat:

                    if (sender.GetType() == DominionBase.Cards.Seaside.TypeClass.IslandMat)
                    {
                        CardCollectionControl cccIsland = dpMatsandPiles.Children.OfType <CardCollectionControl>().SingleOrDefault(ccc => ccc.Name == "cardIsland");
                        if (cccIsland == null)
                        {
                            if (dpMatsandPiles.Children.Count > 0)
                            {
                                Border bDiv = new Border();
                                bDiv.BorderThickness = new Thickness(2);
                                bDiv.BorderBrush     = Brushes.Black;
                                DockPanel.SetDock(bDiv, Dock.Left);
                                dpMatsandPiles.Children.Add(bDiv);
                            }
                            cccIsland         = new CardCollectionControl();
                            cccIsland.Name    = "cardIsland";
                            cccIsland.Padding = new Thickness(0);
                            DockPanel.SetDock(cccIsland, Dock.Left);
                            //cccIsland.Background = Brushes.AliceBlue;
                            cccIsland.PileName = "Island Mat";
                            cccIsland.CardSize = CardSize.Text;
                            dpMatsandPiles.Children.Add(cccIsland);
                        }
                        cccIsland.ExactCount     = true;
                        cccIsland.IsCardsVisible = true;
                        cccIsland.Phase          = PhaseEnum.Action;
                        cccIsland.PlayerMode     = PlayerMode.Waiting;
                        cccIsland.Pile           = deck;
                    }
                    else if (sender.GetType() == DominionBase.Cards.Seaside.TypeClass.NativeVillageMat)
                    {
                        CardCollectionControl cccNativeVillage = dpMatsandPiles.Children.OfType <CardCollectionControl>().SingleOrDefault(ccc => ccc.Name == "cardNativeVillage");
                        if (cccNativeVillage == null)
                        {
                            if (dpMatsandPiles.Children.Count > 0)
                            {
                                Border bDiv = new Border();
                                bDiv.BorderThickness = new Thickness(2);
                                bDiv.BorderBrush     = Brushes.Black;
                                DockPanel.SetDock(bDiv, Dock.Left);
                                dpMatsandPiles.Children.Add(bDiv);
                            }
                            cccNativeVillage         = new CardCollectionControl();
                            cccNativeVillage.Name    = "cardNativeVillage";
                            cccNativeVillage.Padding = new Thickness(0);
                            DockPanel.SetDock(cccNativeVillage, Dock.Left);
                            //cccNativeVillage.Background = Brushes.AliceBlue;
                            cccNativeVillage.PileName = "Native Village Mat";
                            cccNativeVillage.CardSize = CardSize.Text;
                            dpMatsandPiles.Children.Add(cccNativeVillage);
                        }
                        cccNativeVillage.ExactCount     = true;
                        cccNativeVillage.IsCardsVisible = visible;
                        cccNativeVillage.Phase          = PhaseEnum.Action;
                        cccNativeVillage.PlayerMode     = PlayerMode.Waiting;
                        cccNativeVillage.Pile           = deck;
                    }
                    else if (sender.GetType() == DominionBase.Cards.Promotional.TypeClass.PrinceSetAside)
                    {
                        CardCollectionControl cccPrinceSetAside = dpMatsandPiles.Children.OfType <CardCollectionControl>().SingleOrDefault(ccc => ccc.Name == "cardPrinceSetAside");
                        if (cccPrinceSetAside == null)
                        {
                            if (dpMatsandPiles.Children.Count > 0)
                            {
                                Border bDiv = new Border();
                                bDiv.BorderThickness = new Thickness(2);
                                bDiv.BorderBrush     = Brushes.Black;
                                DockPanel.SetDock(bDiv, Dock.Left);
                                dpMatsandPiles.Children.Add(bDiv);
                            }
                            cccPrinceSetAside         = new CardCollectionControl();
                            cccPrinceSetAside.Name    = "cardPrinceSetAside";
                            cccPrinceSetAside.Padding = new Thickness(0);
                            DockPanel.SetDock(cccPrinceSetAside, Dock.Left);
                            cccPrinceSetAside.PileName = "Set Aside";
                            cccPrinceSetAside.CardSize = CardSize.Text;
                            dpMatsandPiles.Children.Add(cccPrinceSetAside);
                        }
                        cccPrinceSetAside.ExactCount     = true;
                        cccPrinceSetAside.IsCardsVisible = true;
                        cccPrinceSetAside.CardSize       = CardSize.Small;
                        cccPrinceSetAside.Phase          = PhaseEnum.Action;
                        cccPrinceSetAside.PlayerMode     = PlayerMode.Waiting;
                        cccPrinceSetAside.Pile           = deck;
                    }

                    break;
                }
            }
            else
            {
                this.Dispatcher.BeginInvoke(new EventHandler <PileChangedEventArgs>(_Player_PileChanged), System.Windows.Threading.DispatcherPriority.Normal, sender, e);
            }
        }