当前位置:编程学习 > wap >>

WP8 BUTTON的问题

做了一个图片按钮,但是当按钮被按下时,为什么图片就没有了,变成 纯色了呢?代码如下:

<Button HorizontalAlignment="Left" Height="182" VerticalAlignment="Top" Width="200" >
                        <Button.Background>
                            <ImageBrush Stretch="Fill" ImageSource="a.jpg"/>
                        </Button.Background>
                    </Button>


PHONE SDK8.0.

如何让图片按下时还是现实图片呢? --------------------编程问答-------------------- BUTTON被按下时,默认状态下前景色和背景色会调换。您可以重写该视图状态,或者自定义BUTTON的模板。
试试设置BUTTON的content属性为<image>,图片放在image中。 --------------------编程问答-------------------- 编辑Button的Pressed状态 --------------------编程问答-------------------- 例子:

   <Application.Resources>
            <Style x:Key="ButtonStyle1" TargetType="Button">
            <Setter Property="Foreground" Value="#FF21BB6E"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Grid>
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="MouseOver"/>
                                        <VisualState x:Name="Pressed">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="rectangle">
                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Thickness>-2</Thickness>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Disabled"/>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Rectangle x:Name="rectangle" Fill="{TemplateBinding Background}" RadiusY="4" RadiusX="4" Stroke="White"/>
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
          
        </Application.Resources>
补充:移动开发 ,  Windows Phone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,