How to apply templated binding to an image button in silverlight

I am new to using Sliverlight. Hope someone can help me. I need image buttons to show that the order is in full or in progress. The function of the click events of these two points is the same for navigating the same page. Currently I have created two Image Buttons on App.xaml, because the source of this image cannot be "TemplateBinding"; the button does not have this property. Is this the best way to do it? If so, please provide a code or link so I can learn from this? Thank.

There is my code:

<Style x:Key="btnComplete" TargetType="Button"  >
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <StackPanel>
                        <Image  Height="50" Width="120" Stretch="none"   Source="../images/btnComplete.png"/>                            
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

      

+3


source to share


2 answers


Here's the ImageButton implementation for wp7. I used this example and changed it for different things: http://silvergeek.net/2011/01/14/imagebutton-control-for-win-phone-7/

Also you can check the controls and the source of the Codeing4Fun code, specifically the buttons. http://coding4fun.codeplex.com/



: Telerik now has ImageButton control for wp7.

+1


source


The easiest way to achieve this is to create a transparent checklist for the button and add an image as content to the button anywhere.

The button code on your page will look like this.

   <Button  Height="100" Width="100" Style="{StaticResource TransparentButtonStyle}" Click="TwitterBtn_Click">
         <Image Height="100" Source="YourIcon.png" Width="100"/>
   </Button>

      



And TransparentButtonStyle can be declared in App.xaml. That's all!

<Style x:Key="TransparentButtonStyle" TargetType="Button">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
               <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}"
                        Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

      

+2


source







All Articles