Centering text vertically and horizontally in TextBlock and PasswordBox in windows store app

前端 未结 3 1295
小鲜肉
小鲜肉 2020-12-18 17:54

I am trying to center the text in a TextBlock and PasswordBox.

In TextBlock I use TextAlignment Property to center the text horizontally, but it still close to the t

3条回答
  •  情话喂你
    2020-12-18 18:32

    TextAlignment is for horizontal alignment. TextBlock itself doesn't suport vertical alignment.

    I suggest put a border around it and let border do vertical alignment:

    
        
    
    

    Or other way would be using height and set padding within textblock.

    For password box use in WPF:

    
    

    For Silverlight you will need to extract the actual template of passwordbox (use blend it allows you to edit template and copy that) then you can change the members (on ContentElement which is of type Border) with template binding like:

    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
    

    You can get the template also at this msdn link.

    For passworbox in Silverlight update password box style in your xaml as this:

            
            
                
                    
                
                
                    
                        
                            
                            
                                
                                    
                                        
                                            
                                        
                                    
                                    
                                
                            
                        
                        
                            
                                
                            
                        
                        
                            
                                
                                
                            
                        
                    
                
    
                
                
                
                
    
                
                
                    
                
            
        
        
    

    Then your PasswordBox can have alignment as such:

    
    

提交回复
热议问题