Windows phone 7 如何在silverlight中应用templateBinding on image按钮

Windows phone 7 如何在silverlight中应用templateBinding on image按钮,windows-phone-7,Windows Phone 7,我对使用Sliverlight是个新手。希望有人能帮助我。我需要图像按钮来显示订单处于完成或处理状态。这两种单击事件功能相同,可以导航同一页面。目前,我在App.xaml上创建了两个客户图像按钮,因为此图像的源无法执行“TemplateBinding”;按钮没有此属性。这是更好的方法吗?如果是这样,你会提供代码或链接,让我可以从中学习吗?谢谢 这是我的代码: <Style x:Key="btnComplete" TargetType="Button" > <S

我对使用Sliverlight是个新手。希望有人能帮助我。我需要图像按钮来显示订单处于完成或处理状态。这两种单击事件功能相同,可以导航同一页面。目前,我在App.xaml上创建了两个客户图像按钮,因为此图像的源无法执行“TemplateBinding”;按钮没有此属性。这是更好的方法吗?如果是这样,你会提供代码或链接,让我可以从中学习吗?谢谢

这是我的代码:

<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>

以下是wp7的ImageButton实现。我使用了这个示例,并对其进行了各种修改:

您还可以查看Codeing4Fun控件和源代码,特别是按钮。


更新:Telerik现在也为wp7提供了一个ImageButton控件。

实现这一点的最简单方法是为按钮创建一个透明的控件模板,并将图像作为内容添加到按钮的任意位置

页面中的按钮代码如下所示

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

透明按钮样式可以在App.xaml中声明。就这些

<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>