Black Background for XAML Editor

后端 未结 5 1332
孤独总比滥情好
孤独总比滥情好 2021-02-04 07:56

I am currently working on a user control that has white text and a transparent background. Unfortunately because the XAML design view within VS2010 has a white background I cann

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 08:08

    As shown in this post, you can condense the code to a single style by using a trigger, since DesignerProperties.IsInDesignMode is an attached property.

    Actually, the code there isn't quite right. It defines an implicit style for TargetType="{x:Type UserControl}", which would be ignored at runtime anyway because your UserControl is actually a derived class -- as Metro Smurf points out in his first point:

    The App.xaml will effect the UserControl at design time because a typed style is applied on an object automatically, but it is not applied to a derived object (UserControl in this case). So, at design time, VS thinks it should apply the style, but at runtime, it will be ignored.

    The right way to do it would be to give it a key and apply it manually to your UserControls:

    
        ...
        
            ...
            
    

    and:

    
    

    As a trigger, this has an extra benefit over setting the background in code-behind -- it will behave properly if the background is explicitly set somewhere else, such as from a containing UserControl:

    
        ...
        
    

    Local values have precedence over style triggers, so on this screen the designer would use a gray background, whereas it would be black when designing MyUserControl stand-alone.

提交回复
热议问题