在我的 Windows phone7 应用程序中,我只需为按钮的每种状态(正常、鼠标悬停、按下、禁用)创建一个具有不同图像的自定义按钮。
如果我只想为每个状态创建一个具有不同背景颜色的自定义按钮,那么我会按照以下步骤完成。
1. Open the page with Expresion Blend
2. Right click button -> Edit Template -> Edit a copy
3. Select Background (In the "Objects and Timeline" Section)
4. Select each "state" under the "state" tab and start adding backgroung color with the "Pressed" state from the properties pannel.
* Ultimately Can add this as follows for all the buttons which require this custom style
Style="{StaticResource ButtonStyle1}"
我尝试按照上述步骤以类似的方式为每个状态分配背景图像。
但问题是,当我自动添加一个状态所需的图像时,它也适用于所有其他状态。所以最终它最终会为所有状态添加相同的图像(最后为任何状态添加图像)。
如果有人能解释在 expression blend for windows phone7 中为每个状态创建具有不同图像的自定义按钮必须遵循的步骤,我将非常感激。提前致谢....!!!
最佳答案
添加图像时,基本上是在设置按钮模板的外观,它与按钮状态无关。为了实现您想要的效果,您可以创建一个包含这两个图像的按钮模板,然后使用状态来显示或隐藏相应的图像。
1. Edit Button Template
2. Add images to the Grid level of the template
3. Highlight each image item and Send to Back to make sure they are behind your border/content
4. Select a State (e.g. Normal, Pressed), highlight one of the images and set the Visibility property to Visible. Highlight the other image and set the Visibility property to Collapsed.
5. Select the other States and do something similar depending on what you what shown.
您的 XAML 应如下所示。为简洁起见,删除了一些内容。
<ControlTemplate TargetType="Button">
<Grid Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="image1">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="image2">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="image1">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="image2">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Image x:Name="image1" HorizontalAlignment="Left" Margin="0,0,0,24" Source="/Images/image1.png" Stretch="Fill" Width="48"/>
<Image x:Name="image2" HorizontalAlignment="Left" Margin="0,0,0,24" Source="/Images/image2.png" Stretch="Fill" Width="48"/>
<Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="{StaticResource PhoneTouchTargetOverhang}">
<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</Grid>
关于Windows phone7 : Create a custom button with different background Images for each state,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12059079/
撕掉我的头发(!)我上次的应用程序更新已被MarketPlace接受并发布,但远程服务器数据连接不起作用/无法从下载的应用程序(来自MarketPlace)进行连接。但是,当我从VisualStudio运行同一个应用程序(接受的XAP)时,使用相同的远程服务器地址工作得很好。为什么!...有没有其他人遇到过这样的事情?这是远程路径:http://www.streamcommunication.com/ZenAwaken/DownloadableCollections.xml我可以将其加载到浏览器并检索XML当我在VisualStudio中时,我可以通过该路径连接并检索文件和使用数据但是
关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。关闭2年前。Improvethisquestion我正在为windowsphone、iphone和android开发一个多平台应用程序。我使用visualstudio(phonesdk)和monoplugin(monotouch和monoforandroidforothertwoplatforms)来做到这一点。您编写代码的c#被编译为所有三个平台的native代码。我的问题(S):我正在寻找基于.net(silve