You encounter a problem with child controls inheriting the properties of a parent class control in WPF development.
For example:
<StackPanelOrientation= "Horizontal"Grid.Row= "1"Background= "Black"Opacity= "0.3"> <LabelContent="{Binding Id}"Foreground= "White"VerticalAlignment= "Center"></Label> <LabelContent="{Binding Name}"Foreground= "White"VerticalAlignment= "Center"></Label> </StackPanel>
At this point two labels inherit the Opacity property of StackPanel, and if you want to not inherit the transparent property, you need to use the brush, the code is as follows:
<SolidColorBrushColor= "Black"Opacity= ". 3"x:key= "Opacitybrush"/><StackPanelOrientation= "Horizontal"Grid.Row= "1"Background="{StaticResource Opacitybrush}"> <LabelContent="{Binding Id}"Foreground= "White"VerticalAlignment= "Center"></Label> <LabelContent="{Binding Name}"Foreground= "White"VerticalAlignment= "Center"></Label> </StackPanel>
WPF parent control transparent child controls are opaque