none
[UWP][XAML]Unset Background Property in XAML RRS feed

  • Question

  • This is probably a strange question, but I want to know how to "unset" the Background (of a Border) in XAML. The Background is being set using the following Style:
    <Style TargetType="Border">
    	<Setter Property="Width" Value="64"/>
    	<Setter Property="Height" Value="64"/>
    	<Setter Property="Background" Value="Transparent"/>
    </Style>
    As you can see, this Style will affect all Border controls because it is unnamed, which is what I want, except for the Background property on only 1 Border (so making this a named Style would mean adding a Style property to a large number of Border(s)). The reason I want to unset this property is because I do not want it to handle events such as PointerPressed, because I want that to be handled by controls underneath it, and I have noticed that not having a Background allows a control to not handle the events (unless you end up clicking/tapping on the Child, but in many cases, especially when it is text, this is not likely enough to be of concern). So my overall goal is to allow the control underneath this Border to handle the PointerPressed event. Any ideas? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Tuesday, September 10, 2019 5:57 PM

Answers

  • Hi,

    Background is the property of the control. There must always be a value.

    If you want the Border to not affect the event capture of the underlying element, you can set its background to x:Null.

    <Style TargetType="Border">
    	...
    	<Setter Property="Background" Value="{x:Null}"/>
    </Style

    Best regards.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Nathan Sokalski Wednesday, September 11, 2019 2:20 PM
    Wednesday, September 11, 2019 2:36 AM

All replies

  • Hi,

    Background is the property of the control. There must always be a value.

    If you want the Border to not affect the event capture of the underlying element, you can set its background to x:Null.

    <Style TargetType="Border">
    	...
    	<Setter Property="Background" Value="{x:Null}"/>
    </Style

    Best regards.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Nathan Sokalski Wednesday, September 11, 2019 2:20 PM
    Wednesday, September 11, 2019 2:36 AM
  • Thanks, I think I forgot about the {x:Null} thing in XAML.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Wednesday, September 11, 2019 2:21 PM