ControlTemplate - Border set CornerRadiusAsk Questions

 Posted on 24 days ago

Hi,

I've a content control with a Border inside. I have to use this control to make different corner radius in a toggle button control (only left corner, center and right corner). To do this I've make 3 differente controltemplate because the CornerRadius of border don't accept a TemplateBinding for that.

It's possible to make an unique controltemplate and passing the corner radius as TemplateBinding?

Thanks

Share On: facebook gplus twitter
profile
Asked by Steve Summit on 24 days ago Score: 52 points
Add Comment:

Comments

1 Answers

0 Corrected Answers
Aproved Answers
0
Profile
Answered by Will Smith on 11/13/2019 7:43:13 AM Score: 54 points

<Window.Resources>
<Style x:Key="TabButton" TargetType="Button">
<Setter Property="TextBlock.TextAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding Background}"
BorderThickness="0,1,1,0" CornerRadius="{TemplateBinding Border.CornerRadius}">
<ContentPresenter x:Name="contentPresenter" Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style
x:Key="TabButtonFirst"
BasedOn="{StaticResource TabButton}"
TargetType="Button">
<Setter Property="Border.CornerRadius" Value="15,0,0,0" />
</Style>

<Style
x:Key="TabButtonLast" BasedOn="{StaticResource TabButton}" TargetType="Button">
<Setter Property="Border.CornerRadius" Value="0,0,0,15" />
</Style>
</Window.Resources>
<StackPanel>
<Button Width="200" Height="30" Content="test" Style="{StaticResource TabButtonFirst}"/>
<Button Width="200" Height="30" Content="test" Style="{StaticResource TabButtonLast}"/>
</StackPanel>

Comments

Add Comment:

Post Your Answers

Existing Members

Sign in to your account
Email Address
Password
New Member?
Sign up and complete profile
Full Name
Email Address
I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the StoodQ newsletters
Guideline to answer a question:

Useful tips to submit your answer
Please read below guidelines before you submit your answer for question.

  • Read and understand question for which you are submitting your answer.
  • Try to avoid grammatical and spell mistake while answering.
  • Do not post any irrelevant information in your answer.
  • Explain your answer with example or any reference link to help who posted question.
  • If you find irrelevant question, please report it to support. Click here to contact support.
  • You agree to the privacy policy and terms of use to submit any contents.

Note: StoodQ is online developers community which helps developer for their difficulty, lets help them with your value contribution.