DataTrigger Usage

后端 未结 2 1219
傲寒
傲寒 2021-01-25 01:55

Here is pseudo code for what I want to implement in xaml

IF vm.AvatarFilePath IS NOT NULL THEN
    Image.Source = {Binding AvatarPath}
ELSE
    If vm.Gender == {         


        
2条回答
  •  逝去的感伤
    2021-01-25 02:32

    You should be able to do this with a couple of MultiDataTriggers:

    
        
        
            
                
                    
                    
                
                
            
    
            
                
                    
                    
                
                
            
            
        
    
    

    These are stating 'when AvatarPath is null AND Gender is female...'

    Further Improvement

    As DataTriggers are applied in the order in which they appear in the XAML, we can remove the need for duplication of the 'Male' settings in the example with the below:

    
        
        
            
                
            
            
                
                    
                    
                
                
            
        
    
    

    Here we are saying:

    1. Set the source to AvatarPath
    2. If AvatarPath is null, set the source to 'Img_Male'
    3. If the AvatarPath is null AND the Gender is female, set the source to 'Img_Female'

提交回复
热议问题