Chessboard in WPF

后端 未结 5 1065
情深已故
情深已故 2021-01-03 07:33

For years I\'ve developed with Winforms, now I want to switch to WPF and make a chessboard. Unfortunately I have no idea where to start. Using WPF makes me very unsure, I\'m

5条回答
  •  借酒劲吻你
    2021-01-03 07:43

    Chess seems like a good fit for WPF's MVVM code pattern.

    The Model will be the logic for the game of chess, sounds like you have that under control. The View will the the WPF look of the game, and the ViewModel will the representation of the game, in which the View can databind to.

    For the view, an ItemsControl using a UniformGrid will work for a 2D representation of the game.

    Here's a start (unchecked)

    
        
            
                
            
        
        
            
                
                    
                
            
        
    
    

    For the above to work, your ViewModel will need to have a ObservableCollection and ChessGridItem should be a DependencyObject exposing DependencyProperties for SquareColor, PieceColor and PieceShape

提交回复
热议问题