Greg McPherran

Hello,

What is the easiest way to modify Button behavior. E.g. How can the border be eliminated I set BorderBrush to Transparent but when hover, the border appears.

Also, how can the corners be made square instead of rounded

Thank You



Re: Windows Presentation Foundation (WPF) Button Style/Template/Properties

Marlon Grech

Hi,

I think the best option is to create a ControlTemplate and restyle the button in what ever manner you want....

This link can help you understand more ....

http://msdn2.microsoft.com/en-us/library/ms771597.aspx





Re: Windows Presentation Foundation (WPF) Button Style/Template/Properties

Greg McPherran

If the ControlTemplate itself does not use a Button then some of the built-in features of the Button are lost or must be implemented. E.g. Rectangle does not have Click event, it has MosuDown. Nor does Rectangle have the automatic Hover and Click behaviors.

What can be done using the Properties of the button regarding eliminating the border including when hovered/clicked and also squaring the Button (i.e. no corner rounding)





Re: Windows Presentation Foundation (WPF) Button Style/Template/Properties

Marlon Grech

I think that this is not exactly right ...

for instance all events will still be raised for example Clikc event etc

if you need to use the properties of the button you can use TemplateBinding for example
if in the template of the button you place a border and you want the content of the border to be the conecnt that is placed in the Content property of the button you can say..

<Viewbox>
<ContentControl Margin="10" Content="{TemplateBinding Content}" />
</Viewbox>


I hope that this made the things more clear





Re: Windows Presentation Foundation (WPF) Button Style/Template/Properties

Greg McPherran

Yes, that's for the Button content e.g. the button text. That's fine. But there is other behavior that comes with Button that I would like to leverage if possible, yet still control the Button border for all cases including Normal, Hover, and Click. I even tried using <Border> but the Hover border of the Button itself still showed up inside my <Border>.




Re: Windows Presentation Foundation (WPF) Button Style/Template/Properties

Carole Snyder

Marion is correct, changing the control template does not lose functionality.*

For example, if you change the control template to the following, the Click event still works.

<Style TargetType="Button">
<!--Set to true to not get any properties from the themes.-->
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Ellipse Fill="{TemplateBinding Background}"/>
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

This example is taken from Styling and Templating, which might be a good place for you to begin.

*There is a caveate. Some classes expect a certain named element to be in the control template. You can verify wether a control needs a certain element by looking for the TemplatePropertyAttribute on the control's ref page. For example, the ComboBox requires a Popup called PART_Popup

[TemplatePartAttribute(Name="PART_Popup", Type=typeof(Popup))]






Re: Windows Presentation Foundation (WPF) Button Style/Template/Properties

Greg McPherran

Can using the template eliminate the border that shows up on Hover but still provide the other Hover highlighting



Re: Windows Presentation Foundation (WPF) Button Style/Template/Properties

Marlon Grech

Hey Carole,

I would really love to start contributing more on WPF issues, is there a forum for WPF only which i can register to

Regards
Marlon





Re: Windows Presentation Foundation (WPF) Button Style/Template/Properties

Greg McPherran

I started another thread. While I appreciate your suggestions for the Button, personal conversation should take place outside of someone's question thread.

I did mark your post and Carole's as answer since another poster also stated that Tempate is the solution.

Thank You Both,

Greg McPherran