Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Writing own (image) button control template
3 replies. Latest Post by sco0ter on July 9, 2009.
(0)
sco0ter
Member
4 points
36 Posts
07-09-2009 5:20 AM |
Hi,
i am currently trying to write my own control template for the Button, which should be a simple ImageButton like in ASP.NET. I want to write a small animation. It should start from about half its size, and onmouseover the button should increase in size (e.g. double).
The Width and Height which the developer which the developer later specifies should be the mouseover width/height. Therefore I need to do a little calculation to set the initial size on half the specified size. But how can I do this calculation in Xaml code?
<Image Source="{TemplateBinding Content}" Width="{TemplateBinding Width} / 2" Height="{TemplateBinding Width} / 2" />
Later I in the Storyboard of my VSM I want to animate the size to {TemplateBinding Width}.
I hope this is somehow possible.
The alternative would be to write a custom control!? But this isn't the right way to go, isn't it?
jay nana...
Contributor
3388 points
624 Posts
07-09-2009 5:27 AM |
I think you can make use of Converter in binding. See here:
http://timheuer.com/blog/archive/2008/07/30/format-data-in-silverlight-databinding-valueconverter.aspx
and here:
http://www.silverlightshow.net/items/Data-Conversion-in-Silverlight-2-Data-Binding.aspx
07-09-2009 6:09 AM |
Yeah, but appearenly Converters are not supported in TemplateBinding.
07-09-2009 6:28 AM |
Problem is solved:
<Image Source="{TemplateBinding Content}" Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Width, Converter={StaticResource ButtonConverter}}" Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource ButtonConverter}}" />
http://blogs.msdn.com/marlat/archive/2009/05/13/silverlight-3-template-binding-vs-relative-binding.aspx