Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.forms 从Xamarin表单中的按钮派生的自定义视图的样式设置不应用文本颜色_Xamarin.forms_Custom Controls_Styling_Resourcedictionary - Fatal编程技术网

Xamarin.forms 从Xamarin表单中的按钮派生的自定义视图的样式设置不应用文本颜色

Xamarin.forms 从Xamarin表单中的按钮派生的自定义视图的样式设置不应用文本颜色,xamarin.forms,custom-controls,styling,resourcedictionary,Xamarin.forms,Custom Controls,Styling,Resourcedictionary,我正在尝试创建一个自定义按钮,其中包含一些从标准按钮类派生的附加行为。这是一个非常简单的类,current的定义如下: public class SimpleCustomButton : Button { public SimpleCustomButton() { } } 为了测试样式设置,我创建了以下页面: <?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns="http://xamari

我正在尝试创建一个自定义按钮,其中包含一些从标准
按钮
类派生的附加行为。这是一个非常简单的类,current的定义如下:

public class SimpleCustomButton : Button
{
    public SimpleCustomButton()
    {
    }
}
为了测试样式设置,我创建了以下页面:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="UIKit.TestPage"
             xmlns:uikit="clr-namespace:UIKit"
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" 
             ios:Page.UseSafeArea="true">
    <ContentPage.Content>
        <StackLayout>
           <Button Text="GlobalStyling normalButton" HorizontalOptions="Center" VerticalOptions="Start"  />
           <uikit:SimpleCustomButton Text="GlobalStyling customButton" HorizontalOptions="Center" VerticalOptions="Start"  />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

我对它应用了以下样式,在app.xaml中全局定义它:

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="UIKit.App"
             xmlns:uikit="clr-namespace:UIKit">
    <Application.Resources>
      <ResourceDictionary>
            <Style TargetType="Button">
                <Setter Property="TextColor" Value="Red" />
                <Setter Property="BackgroundColor" Value="Green" />
                <Setter Property="BorderColor" Value="Red" />
                <Setter Property="BorderRadius" Value="0" />
                <Setter Property="BorderWidth" Value="1" />
            </Style>

            <Style TargetType="uikit:SimpleCustomButton">
                <Setter Property="TextColor" Value="Red" />
                <Setter Property="BackgroundColor" Value="Green" />
                <Setter Property="BorderColor" Value="Red" />
                <Setter Property="BorderRadius" Value="0" />
                <Setter Property="BorderWidth" Value="1" />
            </Style>

        </ResourceDictionary>
    </Application.Resources>
</Application>

因此,
按钮
以绿色背景、红色边框和红色文本颜色呈现。
uikit:SimpleCustomButton
以绿色背景、红色边框和标准蓝色文本颜色呈现

所以我的主要问题是:


为什么只有一些样式属性应用于从
按钮
派生的
uikit:SimpleCustomButton
,而所有这些属性都应用于正常的
按钮

合并的样式?哎呀,这是另一个测试的空资源字典。为了清晰起见,将其移除。检查我是否仍然有相同的结果只是为了确定,我仍然有。您可以尝试的一件事是使用
TargetType=“Button”
,在第一个样式上添加
ApplyToDerivedTypes=“True”
。这将允许您只指定一种样式,而不需要为您的特定按钮类型指定第二种样式。@TaylorD感谢您的建议。不幸的是,这并不能解决问题。请尝试清理您的解决方案删除bin和obj文件夹并重建我无法复制的内容。