Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 关于WP7中的按钮图像_C#_Windows_Xaml_Mobile - Fatal编程技术网

C# 关于WP7中的按钮图像

C# 关于WP7中的按钮图像,c#,windows,xaml,mobile,C#,Windows,Xaml,Mobile,我正在尝试为WP7开发一个应用程序,如果单击按钮,我想更改按钮的背景图像。我该怎么做呢?您需要像这样为按钮创建数据模板 <Style TargetType="Button"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate>

我正在尝试为WP7开发一个应用程序,如果单击按钮,我想更改按钮的背景图像。我该怎么做呢?

您需要像这样为
按钮创建
数据模板

<Style TargetType="Button">
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Image Width="16" Height="16" Stretch="UniformToFill" Source="{Binding}"/>
                        </StackPanel>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

对不起,我是xaml的新手。我要在哪里粘贴xaml代码?您可以将此代码粘贴到页面的
resources
部分,或者控制场景中的任何内容。我指的是与您一起启动的xaml代码,将其放置在资源容器中。请参阅本教程或搜索如何在XAML中使用样式
<Button x:Name="button"  Content="{StaticResource ResourceKey=MyImageSource}"></Button>
button.Content = YourImage;