How to bind click of a button to change the content of a panel (Grid) using XAML

前端 未结 1 1933
离开以前
离开以前 2021-01-07 02:05

I am creating a UI of a WPF Application, and while working on the implementation of the software\'s features, i didn\'t have much experience with creating the UI.

No

1条回答
  •  难免孤独
    2021-01-07 02:47

    I think the XAML-only solution you choose will depend on your specific requirements. In the examples below, I am assuming that XAML-only means you are looking for a solution that does not involve binding to properties in your ViewModel.

    Approach #1:

    If you decide to use a single ToggleButton to show and hide your panel, then this can be done quite easily using Triggers:

    
        
            
                
                    
                        
                            
                        
                        
                    
                    
                        
                            
                        
                        
                            
                        
                    
                
            
        
    
    

    Approach #2:

    If instead you require two buttons (one for showing the panel, one for hiding the panel), then perhaps you could use an EventTrigger instead. This solution is more heavy handed since an EventTrigger does not use Setter's but instead its action is required to be a Storyboard. To emulate the setting of a property like Visibility you can use ObjectAnimationUsingKeyFrames in your Storyboard:

    
        
            
                
            
            

    Hope this helps!

    0 讨论(0)
提交回复
热议问题