Click here to Skip to main content
15,893,588 members
Home / Discussions / WPF
   

WPF

 
QuestionFIPS Error Pin
#realJSOP11-Jun-15 3:41
mve#realJSOP11-Jun-15 3:41 
AnswerRe: FIPS Error Pin
Richard Deeming11-Jun-15 4:24
mveRichard Deeming11-Jun-15 4:24 
GeneralRe: FIPS Error Pin
#realJSOP11-Jun-15 4:42
mve#realJSOP11-Jun-15 4:42 
QuestionHow to get Data from web-server to Silverlight-App Pin
Frygreen10-Jun-15 10:31
Frygreen10-Jun-15 10:31 
AnswerRe: How to get Data from web-server to Silverlight-App Pin
Mycroft Holmes10-Jun-15 13:05
professionalMycroft Holmes10-Jun-15 13:05 
QuestionThoughts On Building My Own Framework Pin
Kevin Marois10-Jun-15 4:42
professionalKevin Marois10-Jun-15 4:42 
AnswerRe: Thoughts On Building My Own Framework Pin
Mycroft Holmes10-Jun-15 13:02
professionalMycroft Holmes10-Jun-15 13:02 
QuestionWPF Button Style quirks Pin
Bernhard Hiller3-Jun-15 2:55
Bernhard Hiller3-Jun-15 2:55 
I played with styles for buttons. I created a rounded button with a radial gradient brush. When it gets focus, a black thick border becomes visible, when the mouse hovers over the button, it receives a transparent border thus "shrinking" the button:
<Style x:Key="RoundedButton" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
    <Setter Property="Background"  Value="{StaticResource GreenGradientBrush}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid>
                    <Rectangle Fill="{TemplateBinding Background}" RadiusX="8" RadiusY="8" />
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="Button.IsFocused" Value="true">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Rectangle Fill="{TemplateBinding Background}" Stroke="Black" StrokeThickness="4" RadiusX="8" RadiusY="8" />
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Trigger>
        <Trigger Property="Button.IsMouseOver" Value="true">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Rectangle Fill="{TemplateBinding Background}" Stroke="Transparent" StrokeThickness="3" RadiusX="8" RadiusY="8" />
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Trigger>
        <Trigger Property="Button.IsEnabled" Value="false">
            <Setter Property="Background"   Value="{StaticResource GrayGradientBrush}"/>
        </Trigger>
    </Style.Triggers>
</Style>

It works. But look at the code. True, it is nicely formatted and hence looks good Big Grin | :-D
It has a smell. So much copy-paste.
I can do better, can't I? What about a TemplateBinding of Stroke and StrokeThickness to BorderBrush and BorderThickness?
<Style x:Key="RoundedButton" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
    <Setter Property="Background"  Value="{StaticResource GreenGradientBrush}"/>
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid>
                    <Rectangle Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}" RadiusX="8" RadiusY="8" />
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="Button.IsFocused" Value="true">
            <Setter Property="BorderBrush" Value="Black"/>
            <Setter Property="BorderThickness" Value="10" />
        </Trigger>
        <Trigger Property="Button.IsMouseOver" Value="true">
            <Setter Property="BorderBrush" Value="Yellow"/>
            <Setter Property="BorderThickness" Value="10" />
        </Trigger>
        <Trigger Property="Button.IsEnabled" Value="false">
            <Setter Property="Background"   Value="{StaticResource GrayGradientBrush}"/>
        </Trigger>
    </Style.Triggers>
</Style>

But it does not work: hardly a reaction is visble with the mouse over the button or on a focussed button. I set the thickness to 10 pixels already, doesn't help.
Why is it necessary to replace the whole Template in the Triggers?
AnswerRe: WPF Button Style quirks Pin
Richard Deeming3-Jun-15 3:22
mveRichard Deeming3-Jun-15 3:22 
GeneralRe: WPF Button Style quirks Pin
Bernhard Hiller3-Jun-15 3:34
Bernhard Hiller3-Jun-15 3:34 
QuestionWPF Window Closing Event To Command Pin
Kevin Marois2-Jun-15 13:12
professionalKevin Marois2-Jun-15 13:12 
QuestionRe: WPF Window Closing Event To Command Pin
Richard Deeming2-Jun-15 21:53
mveRichard Deeming2-Jun-15 21:53 
QuestionWPF Stream Live Video Pin
Kevin Marois1-Jun-15 13:56
professionalKevin Marois1-Jun-15 13:56 
AnswerRe: WPF Stream Live Video Pin
Pete O'Hanlon1-Jun-15 20:41
mvePete O'Hanlon1-Jun-15 20:41 
GeneralRe: WPF Stream Live Video Pin
Kevin Marois2-Jun-15 4:06
professionalKevin Marois2-Jun-15 4:06 
GeneralRe: WPF Stream Live Video Pin
Pete O'Hanlon2-Jun-15 5:20
mvePete O'Hanlon2-Jun-15 5:20 
GeneralRe: WPF Stream Live Video Pin
Kevin Marois2-Jun-15 5:22
professionalKevin Marois2-Jun-15 5:22 
QuestionHow to change Window.Title property? Pin
econy28-May-15 3:13
econy28-May-15 3:13 
AnswerRe: How to change Window.Title property? Pin
Richard Deeming28-May-15 3:48
mveRichard Deeming28-May-15 3:48 
QuestionThe difference of Style on Button and TextBlock, Pin
econy27-May-15 10:15
econy27-May-15 10:15 
AnswerRe: The difference of Style on Button and TextBlock, Pin
Mycroft Holmes27-May-15 13:02
professionalMycroft Holmes27-May-15 13:02 
GeneralRe: The difference of Style on Button and TextBlock, Pin
econy28-May-15 3:10
econy28-May-15 3:10 
AnswerRe: The difference of Style on Button and TextBlock, Pin
Gerry Schmitz1-Jun-15 11:02
mveGerry Schmitz1-Jun-15 11:02 
QuestionWPF ListBoxItem Style Not Working Pin
Kevin Marois26-May-15 9:48
professionalKevin Marois26-May-15 9:48 
QuestionPost Publish Actions Pin
Mycroft Holmes21-May-15 16:32
professionalMycroft Holmes21-May-15 16:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.