-
January 5th, 2011, 10:06 AM
#1
Binding in Style template
I'm trying (failing) to create a button template, to be shared between libraries. The template is (currently) basically a bordered circle inside a bordered circle. In order to make the inner border's size smaller than the outer, I use a Converter on the binding. I'd like to pass in a property of the TemplatedParent as a ConverterParameter but it just doesn't work. Here's my Style def (in a ResourceDictionary):
Code:
<SolidColorBrush x:Key="MyBorderFillColour">Yellow</SolidColorBrush>
<SolidColorBrush x:Key="MyBorderEdgeColour">#ff652f00</SolidColorBrush>
<SolidColorBrush x:Key="MyGeneralFillColour">#ffffffbd</SolidColorBrush>
<s:Int32 x:Key="MyBorderThickness">10</s:Int32>
<l:RelativeSizeConverter x:Key="RelativeSizeConverter" />
<Style x:Key="MyButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Ellipse
Fill="{StaticResource MyBorderFillColour}"
StrokeThickness="2"
Stroke="{StaticResource MyBorderEdgeColour}"
Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}" />
<Ellipse StrokeThickness="2"
Stroke="{StaticResource MyBorderEdgeColour}"
Fill="{StaticResource MyGeneralFillColour}"
Height="{Binding Path=Height,
RelativeSource={RelativeSource TemplatedParent},
Converter={StaticResource RelativeSizeConverter},
ConverterParameter={StaticResource MyBorderThickness}}"
Width="{Binding Path=Width,
RelativeSource={RelativeSource TemplatedParent},
Converter={StaticResource RelativeSizeConverter},
ConverterParameter={Binding Path=BorderThickness,RelativeSource={RelativeSource TemplatedParent}}}" />
<TextBlock
Text="{TemplateBinding Content}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="Black"
FontFamily="Calibri"
FontWeight="Bold"
FontSize="17" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The second Ellipse's Height works using a StaticResource, but Width doesn't work using the TemplatedParent approach.
Any idea how to achieve my aim?!?
Thanks for any help,
Toot
Some cause happiness wherever they go; others, whenever they go.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|