简体   繁体   English

更改 MaterialDesign 中的 TextBox 样式颜色

[英]Change MaterialDesignin TextBox style color

So i have this MaterialDesignin TextBox :所以我有这个MaterialDesignin TextBox

<TextBox Width="300" 
         materialDesign:HintAssist.Hint="User name"
         materialDesign:HintAssist.IsFloating="True"/>

Result without focus:没有焦点的结果:

在此处输入图片说明

Result with focus:重点结果:

在此处输入图片说明

My app.xaml :我的app.xaml

<ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Red.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>

So i want to chanhe the TextBox color for the first picture (without focus) to be something else, i try to change the Foreground property but this not works.因此,我想将第一张图片(无焦点)的TextBox颜色更改为其他颜色,我尝试更改Foreground property但这不起作用。 I mean to change this Gray line color (the red color while focus i want).我的意思是改变这条Gray线的颜色(我想要的焦点时的红色)。

Any suggestions ?有什么建议 ?

You can use whatever you want as a hint.你可以使用任何你想要的作为提示。

<TextBox>
    <materialDesign:HintAssist.Hint>
        <TextBlock Foreground="Red">User name</TextBlock>
    </materialDesign:HintAssist.Hint>
</TextBox>

If you want to apply a common style to all your hints, it might be better to use a style for the SmartHint control, based on the default one.如果您想对所有提示应用一种通用样式,最好基于默认样式为SmartHint控件使用一种样式。

<Style TargetType="materialDesign:SmartHint" BasedOn="{StaticResource {x:Type materialDesign:SmartHint}}">
    <Setter Property="Foreground" Value="Red" />
</Style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM