玻璃表面上的发光标签控件

时间:2010-05-10 16:09:02

标签: c# wpf winforms aero-glass

是否有任何方法,并且任何教程,文章,示例都允许在运行时创建的每个新Label Control都有一个Glow,就像在Vista / 7上一样?

谢谢

1 个答案:

答案 0 :(得分:3)

无法看到附加的图像,因此只能猜测所需的外观应该是什么 - 我在WPF中进行了快速测试,改变了Label的模板并添加了第二个应用了BlurEffect的ContentPresenter。

假设您正在寻找外观,这是一种快速简便的方法。

<Style 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>
                            <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" 
                                Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" 
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" 
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Opacity="0.5">

                                <ContentPresenter.Effect>
                                    <BlurEffect Radius="5"  />
                                </ContentPresenter.Effect>
                            </ContentPresenter>
                            <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" 
                                        Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" 
                                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" 
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>

                        </Grid>
                    </Border>
                <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>