5

Is there any way, and any tutorials, articles, samples around that allow each and every new Label Control created at runtime to have a Glow around it, just like on Vista/7?

Thank you

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • Changed the 'Glow' tag to WPF because its more likely that the solution will be WPF based. – James Westgate May 10 '10 at 16:21
  • This can certainly be accomplished in WPF (probably quite trivially, as well), but can you attach a screenshot which better illustrates the desired effect? – Charlie May 10 '10 at 16:24
  • Appears the image is not hosted properly. Should probably host it on Imageshack or something of that sort. – Charlie May 10 '10 at 16:59
  • @Charlie: Out of curiosity, do you see the binary contents of a GIF image, or an image that reads "I am a lousy bandwidth thief / Don't trust me! / Hosting © ababa.net"? – Jon Purdy May 10 '10 at 17:09
  • If I do right-click, save as, I see the bandwidth thief message. If I just click the link I see the binary. – Charlie May 10 '10 at 17:24
  • For the benefit of all, please do update the image. – bohdan_trotsenko May 10 '10 at 21:46
  • yeh i just uploaded the 40-something kilobyte image to my free hosting account... and they call that stealing. What idiots. –  May 11 '10 at 14:48

1 Answers1

3

Not being able to see the attached image, and therefore only guessing what the desired looks should be - I made a quick test in WPF with altering the template of a Label and adding a second ContentPresenter with a BlurEffect applied.

Assuming the looks is what you are looking for, it's a quick and easy way to go.

<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>
ThomasAndersson
  • 1,844
  • 12
  • 23
  • Wow, thank you for that. One question; Where abouts would I paste this code? Obviously it'll be somewhere inside the XAML file, but where? Sorry, I haven't used WPF very much. But after seeing a few things tonight, I love it! –  May 11 '10 at 14:51
  • Short answer: For the sake of being pragmatic and getting your stuff working, paste this in your window's resource section. ... ...[insert the style here]... Long answer: Read up on resource handling in WPF. – ThomasAndersson May 12 '10 at 08:27