Wpf MaterialDesignInXAML文本框字体颜色为白色(背景色)

Wpf MaterialDesignInXAML文本框字体颜色为白色(背景色),wpf,xaml,Wpf,Xaml,我有以下代码: <Window x:Class="App.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc

我有以下代码:

<Window x:Class="App.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:App"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    TextElement.Foreground="{DynamicResource MaterialDesignBody}"
    mc:Ignorable="d"
    Background="{DynamicResource MaterialDesignPaper}"
    FontFamily="{DynamicResource MaterialDesignFont}"
    Title="e-Sura" Height="376.316" Width="525">
<Grid Margin="0,0,0,-7">
    <Grid.RowDefinitions>
        <RowDefinition Height="120"></RowDefinition>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <materialDesign:Card Padding="32" Margin="16" Grid.Row="0">
        <TextBlock TextAlignment="Center" Style="{DynamicResource MaterialDesignTitleTextBlock}">e-Sura Login</TextBlock>
    </materialDesign:Card>
    <materialDesign:Card Padding="12" Margin="16" Grid.Row="1" Height="180">
        <Grid>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1.2*"></ColumnDefinition>
                <ColumnDefinition Width="3*"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>

            <TextBlock Style="{DynamicResource MaterialDesignTitleTextBlock}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" >User Name :</TextBlock>
            <TextBox Grid.Row="0" Grid.Column="1" Name="UserName" Padding="8,8,8,8" Margin="8,8,8,8" Text="KLPD"></TextBox>

            <TextBlock Style="{DynamicResource MaterialDesignTitleTextBlock}" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right">Password :</TextBlock>
            <PasswordBox Grid.Row="1" Grid.Column="1" Name="Password" Padding="8,8,8,8" Margin="8,8,8,8" Foreground="Black"></PasswordBox>

            <StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal">
                <Button  Padding="8,8,8,8" Margin="8,8,8,8" Width="100">Login</Button>
                <Button  Padding="8,8,8,8" Margin="8,8,8,8" Background="#FFE2D122" BorderBrush="#FFE6D52E" Width="100">Cancel</Button>
            </StackPanel>


        </Grid>
    </materialDesign:Card>
</Grid>

e-Sura登录
用户名:
密码:
登录
取消

运行时名为“UserName”的文本框始终具有与控件背景相似的字体颜色,即白色。 我甚至试着在特定的控件上设置ForeColor=“Black”,但没有成功


我做错了什么?

我认为您没有正确使用样式。使用您发布的代码,我无法看到
textbox
passwordbox
原因是
Padding
Margin
您在这些控件上添加的值

检查以下代码,该代码运行良好,没有任何问题:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplicationTest"
        x:Class="WpfApplicationTest.MainWindow"
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        x:Name="win"
        WindowStartupLocation="CenterOwner"
        TextElement.Foreground="{DynamicResource MaterialDesignBody}"
        mc:Ignorable="d"
        Background="{DynamicResource MaterialDesignPaper}"
        FontFamily="{DynamicResource MaterialDesignFont}"
        Title="e-Sura" Height="376.316" Width="525" FontSize="16">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid Margin="0,0,0,-7">
        <Grid.RowDefinitions>
            <RowDefinition Height="120"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <materialDesign:Card Padding="32" Margin="16" Grid.Row="0">
            <TextBlock TextAlignment="Center" Style="{DynamicResource MaterialDesignTitleTextBlock}">e-Sura Login</TextBlock>
        </materialDesign:Card>
        <materialDesign:Card Padding="12" Margin="16" Grid.Row="1" Height="180">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1.2*"></ColumnDefinition>
                    <ColumnDefinition Width="3*"></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="0" Margin="0, 10"
                           HorizontalAlignment="Right" Text="User Name :"/>
                <TextBox Grid.Row="0" Grid.Column="1" Name="UserName" Text="KLPD"
                         Margin="8, 0" FontSize="20"
                         Style="{DynamicResource MaterialDesignTextBox}"/>

                <TextBlock Grid.Row="1" Grid.Column="0" Margin="0, 10"
                           HorizontalAlignment="Right" Text="Password :"/>
                <PasswordBox Grid.Row="1" Grid.Column="1"
                             Style="{DynamicResource MaterialDesignPasswordBox}"
                             Margin="8, 0" FontSize="20"
                             Name="Password" />

                <StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal">
                    <Button  Padding="8" Margin="8" Width="100">Login</Button>
                    <Button  Padding="8" Margin="8" Background="#FFE2D122" BorderBrush="#FFE6D52E" Width="100">Cancel</Button>
                </StackPanel>


            </Grid>
        </materialDesign:Card>
    </Grid>
</Window>

e-Sura登录
登录
取消

MaterialDesignBody的定义是什么?看起来它可能继承了这个作为前景。或者您在某个地方定义了默认样式和/或模板?