How do I make a RadioButton's Bullet align top?

前端 未结 3 1941
我寻月下人不归
我寻月下人不归 2020-12-17 19:12

I have a multiline radio button and I want the bullet to be to the left of the content (as default) aligned to the top of the radio button control. What\'s the easiest way t

3条回答
  •  温柔的废话
    2020-12-17 19:24

    Note: Be sure to check out Rachel's answer - she takes this one stage further into a generic template


    First of all don't waste your time with VerticalAlignment or VerticalContentAlignment (or even ControlTemplate). They're not going to do what you want or might expect.

    As described on MSDN a BulletDecorator (which is the control that CheckBox and RadioButton uses to render a radio/check button) will set the position of the icon automatically. You have no additional control over this:

    A Bullet always aligns with the first line of text when the Child object is a text object. If the Child object is not a text object, the Bullet aligns to the center of the Child object.

    Unless you change the control template (unnecessary) you'll only be able to position the radio/check icon at the top if the content is text.

    So if you do something like this it won't look good because you won't be able to move the icon no matter how many VerticalAlignment properties you try to set.

    
        
            
            
        
    
    

    BUT fortunately you can put pretty much anything you want in a TextBlock using InlineUIContainer. The text (or content) in the first line will dictate the position of the icon automatically. If you want something underneath the first line that isn't text, just use and then

    Here's an example that has an oversized TextBox to show more clearly what's happening.

    
    
        
    
            
    
            
                          
            
    
            
                
                
            
    
                
    
            
                
                    
                    
                
            
    
        
    
    

提交回复
热议问题