Skip to main content

Microsoft Silverlight

Answered Question Writing own (image) button control templateRSS Feed

(0)

sco0ter
sco0ter

Member

Member

4 points

36 Posts

Writing own (image) button control template

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?

 So I need something like that in my template:
<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 nanavati
jay nana...

Contributor

Contributor

3388 points

624 Posts

Re: Writing own (image) button control template

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

Jay K Nanavaty
www.technologyopinion.com
Mark as answer if it helps. It will also help others...

sco0ter
sco0ter

Member

Member

4 points

36 Posts

Re: Writing own (image) button control template

 Yeah, but appearenly Converters are not supported in TemplateBinding.

sco0ter
sco0ter

Member

Member

4 points

36 Posts

Answered Question

Re: Writing own (image) button control template

 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

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities