Windows Phone 8按钮色调颜色和图像



所以我在玩Windows Phone 8,考虑将我们的iOS应用程序移植到该平台上,所以我有所有想要使用的资产,但有一件事我不知道是否有办法更改图像的色调。例如,在iOS中,我可以简单地做一些类似[UIButton appearance] setTintColor:[UIColor redColor]]的事情,然后所有的按钮都会在我使用的图像上显示红色。我只是不确定Windows Phone是否有类似的东西,或者我是否需要更新Windows Phone的资产,使其具有我想用于此平台的确切色调。

您可以通过几种方法来实现这一点。一种是创建一种样式,为按钮定义红色色调覆盖。在Visual Studio中,您可以创建按钮并右键单击它(在设计器中),然后选择编辑模板->编辑副本。。。

当您这样做时,您将获得按钮的默认样式。向下滚动到Border元素所在的位置,该元素包含ContentControl。一个Border只能有一个子级,因此您需要用网格包装ContentControl。在ContentControl下添加另一个网格,并给它一个红色背景和低透明度,这样你就可以透过它看到

这只是风格的边界部分

    <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="{StaticResource PhoneTouchTargetOverhang}">
    <Grid>
        <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
        <Grid Background="Red" Opacity=".4"></Grid>
    </Grid>
</Border>

另一种方法(也是更高级的方法)是创建一个自定义控件,允许您在其上设置色调。此解决方案与上面的解决方案非常相似,并且将使用相同的样式,但background将绑定(使用TemplateBinding)到新控件上的DependencyProperty(它将从Button派生),而不是像上面那样将背景设置为红色。

最新更新