【问题标题】:Effect on all buttons in Xamarin Forms对 Xamarin Forms 中所有按钮的影响
【发布时间】:2018-06-28 16:02:28
【问题描述】:

我正在尝试对我的所有按钮产生影响,但我似乎无法正确配置。

这就是我现在拥有的:

<ResourceDictionary>
    <ControlTemplate x:Key="ButtonTemplate" >
        <Grid RowSpacing="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
            <ContentPresenter Grid.Row="0" Grid.Column="0" >
                <ContentPresenter.Effects>
                    <effects:ShadowEffect Radius="5" DistanceX="5" DistanceY="5">
                        <effects:ShadowEffect.Color>
                            <OnPlatform x:TypeArguments="Color">
                                <On Platform="iOS" Value="Black" />
                                <On Platform="Android" Value="White" />
                                <On Platform="UWP" Value="Red" />
                            </OnPlatform>
                        </effects:ShadowEffect.Color>
                    </effects:ShadowEffect>
                </ContentPresenter.Effects>
            </ContentPresenter>

        </Grid>
    </ControlTemplate>

    <Style TargetType="{x:Type Button}">
        <Setter Property="ControlTemplate" Value="{StaticResource ButtonTemplate}"></Setter>
    </Style>
</ResourceDictionary>

但这会引发Can't resolve ControlTemplateProperty on Button

有人知道怎么做吗?

【问题讨论】:

    标签: xaml xamarin xamarin.forms uwp-xaml


    【解决方案1】:

    正如您在 Xamarin.Forms Guides 看到的那样,控制模板不适用于 Button。

    可以通过设置将 ControlTemplate 应用于以下类型 它们的 ControlTemplate 属性:

    • 内容页面
    • 内容视图
    • 模板化页面
    • 模板视图

    错误Can't resolve ControlTemplateProperty on Button 是有道理的。 Button 继承自 View,而不是需要的 TemplatedView

    所以关于你的主要观点,效果不能直接被样式消耗,但你可以通过附加属性来实现这一点。这里有一些很好的参考:

    希望对你有帮助(抱歉我的英语不好)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-23
      • 2021-07-22
      • 2013-06-26
      • 1970-01-01
      • 2017-07-01
      • 1970-01-01
      • 2020-01-22
      • 2015-11-28
      相关资源
      最近更新 更多