在 Silverlight 中使用光栅图像作为按钮
我有 Photoshop 提供的不同按钮状态的按钮。
看起来像这样 该
<Button x:Name="ResultsBtn" Click="ResultsBtn_Click" FontSize="27" BorderThickness="0" Padding="-10" Margin="-10">
<Grid>
<Image Source="..But_01_Idle.png" Width="496"/>
<TextBlock Text="Results" Margin="174,21,172,23" Width="90" Height="40" Foreground="White" />
</Grid>
</Button>
按钮看起来只适合一种状态。
我想使用表达式混合来记录状态并更改图像后面的背景(在本例中为外发光)或更改状态更改时的源。
我注意到混合似乎只记录位置和变换,而不记录属性的变化。
我应该在代码中执行此操作,还是以特定格式发送 Photoshop 文件,以便可以通过混合自动转换它
I have buttons supplied to me from photoshop for different button states.
It looks like this
<Button x:Name="ResultsBtn" Click="ResultsBtn_Click" FontSize="27" BorderThickness="0" Padding="-10" Margin="-10">
<Grid>
<Image Source="..But_01_Idle.png" Width="496"/>
<TextBlock Text="Results" Margin="174,21,172,23" Width="90" Height="40" Foreground="White" />
</Grid>
</Button>
The button looks right for just one state.
I want to use expression blend to record a state and change the background behind an image (in this instance an outer glow) or change the source on a state change.
I've noticed that blend only seems to record position and transforms and not changes in attributes.
Should I be doing this in code or rather have the photoshop file sent in a particular format so that it can be automatically converted by blend
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我实际上对 Blend 感到非常惊讶:它似乎不允许您对源属性进行动画处理。然而,Silverlight 允许这样做,所以我认为 WP7 也会允许它;这看起来像是 Blend 4 中的一个错误。但是,我仍然不建议使用基于图像的方法,因为当显着放大或缩小时,图像会变形并且看起来很糟糕/像素化。更好的方法是编辑按钮的控件模板并修改它以匹配您的参考图稿。您甚至可以使用文件 ->导入 Adobe Photoshop 文件...将基本图稿拖入 Blend。然后只需将其拖入控制模板即可。
如果您执意要使用图像(这会增加 XAP 的大小并实际上导致加载 UserControl 的加载时间变慢),您可以在 Blend 中按如下方式进行操作:
Okay, I'm actually quite surprised at Blend: it does not seem to allow you to animate the source property. However, Silverlight allows it so I assume WP7 will also allow it; this looks like a bug in Blend 4. However, I still would not recommend it using an image based approach because the images will deform and look bad/pixelated when significantly scaled up or down. A better approach is to edit your button's control template and modify it to match your reference artwork. You can even using File -> Import Adobe Photoshop File ... to pull the basic artwork into Blend. Then it's just a matter of shuffling it into the control template.
If you're dead set on using images (which will increase the size of your XAP and actually cause slower load UserControl load times), you can go about it as follows in Blend:
视觉状态是用动画构建的,因此您只能更改可以动画化的内容(并期望典型结果)。我从未尝试过,但我的直觉告诉我图像源无法进行动画处理,因此 VSM 可能不是管理该问题的可行方法。
然而,不透明度可以设置动画,因此您可以将两个图像都放在 ytour 按钮中,并通过状态控制它们的不透明度。只是一个想法。
Visual States are built with animations, so you can only change things that can be animated (and expect typical results). I've never tried it, but my instinct tells me an Image source cannot be animated so the VSM is probably not a viable way to manage that.
Opacity, however, can be animated, so you could have both Image's in ytour button and control their Opacity with States. Just a thought.
您必须创建一个 ControlTemplate:
按钮代码:
在您的资源字典中:
然后,在 Blend 中编辑模板,您将找到 Mike 所说的状态。使用“属性”面板隐藏/显示您想要设置样式的每个状态的图像,您应该完成了。
You have to create a ControlTemplate:
Code for Button:
In your Resource Dictionary:
Then, in Blend, Edit the Template and you'll find the States as Mike said. Use the Properties panel to hide / show your images for each state you want to style and you should be done.