I had a problem with the implementation of the decorator, because it stood in the answer of Paya, so I will show how it can be wrapped in a full-fledged ready-to-use style resource that can be applied to any label in which the glass effect will be displayed, as well as disable the shortcut when disconnect and save alignment, border, etc .:
<Style x:Key="GlassLabelStyle" TargetType="{x:Type Label}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Label}"> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True"> <Grid> <Decorator> <Decorator.Effect> <DropShadowEffect BlurRadius="7" Color="White" ShadowDepth="0" /> </Decorator.Effect> <Decorator> <Decorator.Effect> <DropShadowEffect BlurRadius="7" Color="White" ShadowDepth="0" /> </Decorator.Effect> <Decorator> <Decorator.Effect> <DropShadowEffect BlurRadius="7" Color="White" ShadowDepth="0" /> </Decorator.Effect> <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> </ContentPresenter> </Decorator> </Decorator> </Decorator> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> <Setter Property="Opacity" Value="0.5"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
If the style is in your window or application resources, you can apply it like this:
<Label Style="{StaticResource GlassLabelStyle}"
And while I am in this, I ran into a problem with TextBox too, where you simply cannot change the background color when the control is disabled (it just keeps returning to white), so someone realized that you need to redefine the whole template! See ( https://stackoverflow.com/a/166778/ ). So, here is a ready-to-use style that will make the text field translucent when turned off (looks great on glass) and make its background translucent white with a more visible border if it is turned on:
<SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#01000000" /> <SolidColorBrush x:Key="DisabledBorderBrush" Color="#40000000" /> <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#88ffffff" /> <Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}"> <Setter Property="Background" Value="#88ffffff"/> <Setter Property="BorderBrush" Value="Black"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="TextBox"> <Border Name="Bd" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true"> <ScrollViewer Name="PART_ContentHost" Background="{TemplateBinding Background}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Value="{StaticResource DisabledBackgroundBrush}" Property="Background" /> <Setter Value="{StaticResource DisabledBorderBrush}" Property="BorderBrush"/> <Setter Value="{StaticResource DisabledForegroundBrush}" Property="Foreground" /> <Setter TargetName="PART_ContentHost" Property="Background" Value="{StaticResource DisabledBackgroundBrush}"/> <Setter TargetName="PART_ContentHost" Property="BorderBrush" Value="{StaticResource DisabledBackgroundBrush}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
Triynko
source share