Игнорируется установленное для TextBox значение Background (WPF)

Рейтинг: 0Ответов: 0Опубликовано: 13.02.2023

Второй раз уже сталкиваюсь с такой вот хренью в WPF, не могу понять в чем дело и как это правильно побороть.

Суть проблемы заключается в том, что игнорируется в TextBox установленное значение свойства Background. Сначала значение свойства было прописано в стилях, но пробовал прописывать значение и непосредственно в XAML, но значение игнорируется и бекграунд остается прозрачным — т.е. ровно того же цвета, как и бекграунд родительского контрола.

Скриншот приложения

Кто сталкивался с такой хренью или если кто-то понимает в чем проблема, объясните плиз, буду очень благодарен!

UPDATED 14.02.2023 00:56:

<UserControl x:Class="Telesyk.SmartTable.Application.UI.Controls.Books.Left"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:local="clr-namespace:Telesyk.SmartTable.Application.UI.Controls.Books"
    mc:Ignorable="d" 
    d:DesignHeight="450" d:DesignWidth="800">
    <DockPanel Style="{StaticResource SmartTable.Filter}">
        <Border Style="{DynamicResource SmartTable.Caption}" DockPanel.Dock="Top">
            <TextBlock x:Name="TextCaption" />
        </Border>
        <DockPanel Style="{DynamicResource SmartTable.Info}">
            <TextBlock x:Name="TextBookQuantityCaption" Style="{DynamicResource SmartTable.Title}" />
            <TextBlock x:Name="TextBookQuantity" Text="27 314" />
        </DockPanel>
        <DockPanel Style="{DynamicResource SmartTable.Info}">
            <TextBlock x:Name="TextBookRentsCaption" Style="{DynamicResource SmartTable.Title}" />
            <TextBlock x:Name="TextBookRents" Text="117" />
        </DockPanel>
        <Grid Style="{DynamicResource SmartTable.Fields}">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Style="{DynamicResource SmartTable.Empty}" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3">
                <TextBlock><Run x:Name="TextTitleName" />:</TextBlock>
                <TextBox x:Name="TextName" />
            </StackPanel>
            <StackPanel Grid.Row="1" Grid.Column="0">
                <TextBlock><Run x:Name="TextTitleAuthor" />:</TextBlock>
                <TextBox x:Name="TextAuthor" />
            </StackPanel>
            <StackPanel Grid.Row="1" Grid.Column="2">
                <TextBlock><Run x:Name="TextTitlePublisher" />:</TextBlock>
                <TextBox x:Name="TextPublisher" />
            </StackPanel>
            <StackPanel Grid.Row="2" Grid.Column="0">
                <TextBlock><Run x:Name="TextTitleYear" />: <Run Style="{DynamicResource SmartTable.Comment}" Text="(+/-2)" /></TextBlock>
                <TextBox x:Name="TextYear" />
            </StackPanel>
            <StackPanel Grid.Row="2" Grid.Column="2">
                <TextBlock><Run x:Name="TextTitlePages" />: <Run Style="{DynamicResource SmartTable.Comment}" Text="(+/-25)" /></TextBlock>
                <TextBox x:Name="TextPages" />
            </StackPanel>
            <StackPanel Grid.Row="3" Grid.Column="0">
                <TextBlock><Run x:Name="TextTitleGenre" />:</TextBlock>
                <ComboBox x:Name="SelectGenre" />
            </StackPanel>
            <StackPanel Grid.Row="3" Grid.Column="2">
                <TextBlock><Run x:Name="TextTitleCover" />:</TextBlock>
                <ComboBox x:Name="SelectCover" />
            </StackPanel>
        </Grid>
        <StackPanel Style="{DynamicResource SmartTable.ButtonsArea}" DockPanel.Dock="Top">
            <Button x:Name="ButtonReset" />
        </StackPanel>
    </DockPanel>
</UserControl>

Этот контрол добавляется в этом контрле:

<UserControl x:Class="Telesyk.SmartTable.Application.UI.Controls.Layout"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:local="clr-namespace:Telesyk.SmartTable.Application.UI.Controls"
    xmlns:books="clr-namespace:Telesyk.SmartTable.Application.UI.Controls.Books"
    xmlns:root="clr-namespace:Telesyk.SmartTable.UI.Controls;assembly=Telesyk.SmartTable.RootControls"
    mc:Ignorable="d" 
    d:DesignHeight="320" d:DesignWidth="500" Background="White">
    <root:RootLayout x:Name="ControlLayout">
        <root:RootLayout.Header>
            <local:Header />
        </root:RootLayout.Header>
        <root:RootLayout.Content>
            <TabControl x:Name="TabSections">
                <TabItem x:Name="TabBegin" Tag="Begin">
                    <root:RootSection>
                        <root:RootSection.Content>
                            <local:Main Tag="Begin" />
                        </root:RootSection.Content>
                    </root:RootSection>
                </TabItem>
                <TabItem x:Name="TabBooks" Tag="BookRegistry">
                    <root:RootSection>
                        <root:RootSection.LeftPanel>
                            <books:Left Tag="BookRegistry" />
                        </root:RootSection.LeftPanel>
                        <root:RootSection.Content>
                            <books:Main />
                        </root:RootSection.Content>
                    </root:RootSection>
                </TabItem>
                <TabItem x:Name="TabReadership" Tag="Readership">
                    <root:RootSection>
                        <root:RootSection.LeftPanel>
                            <local:Left Tag="Readership" />
                        </root:RootSection.LeftPanel>
                        <root:RootSection.Content>
                            <local:Main />
                        </root:RootSection.Content>
                    </root:RootSection>
                </TabItem>
                <TabItem x:Name="TabParking" Tag="BookParking">
                    <root:RootSection>
                        <root:RootSection.LeftPanel>
                            <local:Left Tag="BookParking" />
                        </root:RootSection.LeftPanel>
                        <root:RootSection.Content>
                            <local:Main />
                        </root:RootSection.Content>
                    </root:RootSection>
                </TabItem>
                <TabItem x:Name="TabOverdues" Tag="Overdues">
                    <root:RootSection>
                        <root:RootSection.LeftPanel>
                            <local:Left Tag="Overdues" />
                        </root:RootSection.LeftPanel>
                        <root:RootSection.Content>
                            <local:Main />
                        </root:RootSection.Content>
                    </root:RootSection>
                </TabItem>
                <TabItem x:Name="TabQueues" Tag="Queues">
                    <root:RootSection>
                        <root:RootSection.LeftPanel>
                            <local:Left Tag="Queues" />
                        </root:RootSection.LeftPanel>
                        <root:RootSection.Content>
                            <local:Main />
                        </root:RootSection.Content>
                    </root:RootSection>
                </TabItem>
            </TabControl>
        </root:RootLayout.Content>
        <root:RootLayout.Footer>
            <local:Footer />
        </root:RootLayout.Footer>
    </root:RootLayout>
</UserControl>

Контрол лайоута — это единственный контрод окна.

А вот root контролы из другой сборки. В отдельной сборке они находятся потому, что солюшн состоит из двух WPF приложений: первое — это само приложение, второе — конфигуратор, и в обоих приложениях используются эти рутовые контролы. Вот их представления:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Telesyk.SmartTable.UI.Controls">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Telesyk.SmartTable.RootControls;component/Themes/Styles.xaml" />
    </ResourceDictionary.MergedDictionaries>
    <Style TargetType="{x:Type local:RootLayout}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:RootLayout}">
                    <Grid Style="{StaticResource SmartTable.Layout}">
                        <Grid.RowDefinitions>
                            <RowDefinition Style="{DynamicResource SmartTable.HeaderArea}" />
                            <RowDefinition Style="{DynamicResource SmartTable.CenterArea}" />
                            <RowDefinition Style="{DynamicResource SmartTable.FooterArea}" />
                        </Grid.RowDefinitions>
                        <DockPanel Name="ContainerHeader" Style="{DynamicResource SmartTable.Header}">
                            <ContentPresenter Content="{TemplateBinding Header}" />
                        </DockPanel>
                        <DockPanel Style="{DynamicResource SmartTable.Center}">
                            <Border>
                                <ContentPresenter Content="{TemplateBinding Content}" />
                            </Border>
                        </DockPanel>
                        <DockPanel Style="{DynamicResource SmartTable.Footer}">
                            <ContentPresenter Content="{TemplateBinding Footer}" />
                        </DockPanel>
                        <Canvas Style="{DynamicResource SmartTable.Resizer}">
                            <Image x:Name="ImageResizer" Style="{StaticResource SmartTable.ImageResizer}" />
                        </Canvas>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type local:RootSection}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:RootSection}">
                    <Grid Style="{StaticResource SmartTable.Section}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="ColumnPanel" Style="{DynamicResource SmartTable.PanelArea}" />
                            <ColumnDefinition Style="{DynamicResource SmartTable.Splitter}" />
                            <ColumnDefinition Style="{DynamicResource SmartTable.ContentArea}" />
                        </Grid.ColumnDefinitions>
                        <DockPanel x:Name="PanelLeft" Grid.Column="0" Style="{DynamicResource SmartTable.LeftPanel}">
                            <ScrollViewer x:Name="ContainerLeft">
                                <ContentPresenter Content="{TemplateBinding LeftPanel}" />
                            </ScrollViewer>
                        </DockPanel>
                        <GridSplitter x:Name="ControlSplitter" Grid.Column="1" />
                        <DockPanel x:Name="PanelContent" Grid.Column="2" Style="{DynamicResource SmartTable.ContentPanel}">
                            <ScrollViewer x:Name="ContainerContent">
                                <ContentPresenter Content="{TemplateBinding Content}" />
                            </ScrollViewer>
                        </DockPanel>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

Стили root контролов:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="SmartTable.Layout" TargetType="Grid">
        <Setter Property="Background" Value="White" />
        <Style.Resources>
            <Style x:Key="SmartTable.HeaderArea" TargetType="RowDefinition">
                <Setter Property="Height" Value="40" />
            </Style>
            <Style x:Key="SmartTable.CenterArea" TargetType="RowDefinition">
            </Style>
            <Style x:Key="SmartTable.FooterArea" TargetType="RowDefinition">
                <Setter Property="Height" Value="25" />
            </Style>
            <Style x:Key="SmartTable.Header" TargetType="DockPanel">
                <Setter Property="Grid.Row" Value="0" />
                <Setter Property="Background" Value="LightGray" />
            </Style>
            <Style x:Key="SmartTable.Center" TargetType="DockPanel">
                <Setter Property="Grid.Row" Value="1" />
                <Style.Resources>
                    <Style TargetType="TabControl">
                        <Setter Property="Margin" Value="5" />
                        <Setter Property="Padding" Value="0" />
                    </Style>
                    <Style TargetType="TabItem">
                        <Setter Property="Margin" Value="0,0,-1,0" />
                        <Setter Property="Padding" Value="6,3" />
                    </Style>
                    <Style TargetType="Border">
                        <Setter Property="BorderThickness" Value="0,1" />
                        <Setter Property="BorderBrush" Value="#acacac" />
                        <Setter Property="Margin" Value="0" />
                    </Style>
                </Style.Resources>
            </Style>
            <Style x:Key="SmartTable.Footer" TargetType="DockPanel">
                <Setter Property="Grid.Row" Value="2" />
                <Setter Property="Background" Value="LightGray" />
            </Style>
            <Style x:Key="SmartTable.Resizer" TargetType="Canvas">
                <Setter Property="Grid.Row" Value="2" />
                <Setter Property="VerticalAlignment" Value="Bottom" />
                <Setter Property="HorizontalAlignment" Value="Right" />
                <Setter Property="Panel.ZIndex" Value="10" />
                <Setter Property="Cursor" Value="SizeNWSE" />
            </Style>
        </Style.Resources>
    </Style>
    <Style x:Key="SmartTable.Section" TargetType="Grid">
        <Style.Resources>
            <Style x:Key="SmartTable.PanelArea" TargetType="ColumnDefinition">
                <Setter Property="MinWidth" Value="60" />
                <Setter Property="MaxWidth" Value="380" />
            </Style>
            <Style x:Key="SmartTable.Splitter" TargetType="ColumnDefinition">
                <Setter Property="Width" Value="4" />
            </Style>
            <Style x:Key="SmartTable.MainArea" TargetType="ColumnDefinition">
                <Setter Property="Width" Value="Auto" />
            </Style>
            <Style x:Key="SmartTable.LeftPanel" TargetType="DockPanel">
                <Setter Property="Margin" Value="0,0,0,0" />
                <Setter Property="LastChildFill" Value="True" />
                <Style.Resources>
                    <Style TargetType="ScrollViewer">
                        <Setter Property="Margin" Value="0,0,0,0" />
                        <Setter Property="Background" Value="WhiteSmoke" />
                        <Setter Property="HorizontalScrollBarVisibility" Value="Auto" />
                        <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
                    </Style>
                </Style.Resources>
            </Style>
            <Style TargetType="GridSplitter">
                <Setter Property="Cursor" Value="SizeWE" />
                <Setter Property="BorderThickness" Value="1,0,0,0" />
                <Setter Property="BorderBrush" Value="#d1d3d6" />
                <Setter Property="Width" Value="4" />
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="HorizontalAlignment" Value="Center" />
                <Setter Property="VerticalAlignment" Value="Stretch" />
                <Setter Property="Panel.ZIndex" Value="1" />
            </Style>
            <Style x:Key="SmartTable.ContentPanel" TargetType="DockPanel">
                <Setter Property="Background" Value="GhostWhite" />
                <Style.Resources>
                    <Style TargetType="ScrollViewer">
                        <Setter Property="Margin" Value="-2,0,0,0" />
                        <Setter Property="Padding" Value="0,0,0,0" />
                        <Setter Property="Background" Value="GhostWhite" />
                        <Setter Property="BorderThickness" Value="0" />
                        <Setter Property="HorizontalScrollBarVisibility" Value="Auto" />
                        <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
                    </Style>
                </Style.Resources>
            </Style>
            <Style TargetType="ScrollViewer">
                <Setter Property="HorizontalScrollBarVisibility" Value="Auto" />
                <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
            </Style>
        </Style.Resources>
    </Style>
    <Style x:Key="SmartTable.ImageResizer" TargetType="Image">
        <Setter Property="Source" Value="pack://application:,,,/Telesyk.SmartTable.RootControls;component/Themes/Images/resizer.png" />
        <Setter Property="Width" Value="16" />
        <Setter Property="Height" Value="16" />
        <Setter Property="Canvas.Right" Value="1" />
        <Setter Property="Canvas.Bottom" Value="1" />
    </Style>
</ResourceDictionary>

Так же есть еще проект UIComponents который используется обоими приложениями, который в т.ч. имеет три файла стилей: Buttons.xaml — со стилями для кнопок приложения; ScrollViewer.xaml — со стилями для скроллвьюверов; и Styles.xaml со общими стилями для обоих приложений. Два первых я не буду публиковать, а вот последний вот он:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <!--<SolidColorBrush x:Key="SmartTable.TitleText" Color="#4b6c86" />-->
    <SolidColorBrush x:Key="SmartTable.TitleText" Color="#2c6c8d" />
    <Style x:Key="SmartTable.Filter" TargetType="DockPanel">
        <Setter Property="LastChildFill" Value="False" />
        <Style.Resources>
            <Style x:Key="SmartTable.Caption" TargetType="Border">
                <Setter Property="DockPanel.Dock" Value="Top" />
                <Setter Property="Margin" Value="8,6" />
                <Setter Property="Background" Value="#d1d3d6" />
                <Setter Property="BorderBrush" Value="DarkGray" />
                <Setter Property="BorderThickness" Value="1" />
                <Setter Property="CornerRadius" Value="3" />
                <Setter Property="SnapsToDevicePixels" Value="True" />
                <Style.Resources>
                    <Style TargetType="TextBlock">
                        <Setter Property="Foreground" Value="{StaticResource SmartTable.TitleText}" />
                        <Setter Property="FontSize" Value="16" />
                        <Setter Property="Margin" Value="6,2,6,4" />
                    </Style>
                </Style.Resources>
            </Style>
            <Style x:Key="SmartTable.Fields" TargetType="Grid">
                <Setter Property="DockPanel.Dock" Value="Top" />
                <Setter Property="Margin" Value="8,12,8,0" />
                <Style.Resources>
                    <Style TargetType="TextBox">
                        <Setter Property="Background" Value="White" />
                        <Setter Property="Height" Value="21" />
                        <Setter Property="Padding" Value="1" />
                    </Style>
                    <Style TargetType="ComboBox">
                        <Setter Property="Background" Value="White" />
                        <Setter Property="Height" Value="21" />
                        <Setter Property="Padding" Value="1" />
                    </Style>
                    <Style TargetType="StackPanel">
                        <Setter Property="Margin" Value="0,0,0,4" />
                        <Style.Resources>
                            <Style TargetType="TextBlock">
                                <Setter Property="Foreground" Value="{StaticResource SmartTable.TitleText}" />
                                <Setter Property="Margin" Value="0,0,0,2" />
                            </Style>
                            <Style x:Key="SmartTable.Comment" TargetType="Run">
                                <Setter Property="Foreground" Value="Gray" />
                                <Setter Property="FontSize" Value="10" />
                            </Style>
                        </Style.Resources>
                    </Style>
                    <Style x:Key="SmartTable.Comment" TargetType="Run">
                        <Setter Property="Foreground" Value="LightGray" />
                        <Setter Property="FontSize" Value="10" />
                    </Style>
                </Style.Resources>
            </Style>
            <Style x:Key="SmartTable.Info" TargetType="DockPanel">
                <Setter Property="DockPanel.Dock" Value="Top" />
                <Setter Property="Margin" Value="8,6,10,0" />
                <Style.Resources>
                    <Style TargetType="TextBlock">
                        <Setter Property="DockPanel.Dock" Value="Right" />
                        <Setter Property="HorizontalAlignment" Value="Right" />
                        <Setter Property="FontSize" Value="14" />
                        <Setter Property="Foreground" Value="Gray" />
                    </Style>
                    <Style x:Key="SmartTable.Title" TargetType="TextBlock">
                        <Setter Property="DockPanel.Dock" Value="Left" />
                        <Setter Property="Foreground" Value="{StaticResource SmartTable.TitleText}" />
                        <Setter Property="FontSize" Value="14" />
                    </Style>
                </Style.Resources>
            </Style>
            <Style x:Key="SmartTable.Empty" TargetType="ColumnDefinition">
                <Setter Property="MaxWidth" Value="8" />
            </Style>
            <Style x:Key="SmartTable.Text" TargetType="TextBlock">
                <Setter Property="DockPanel.Dock" Value="Top" />
                <Setter Property="Margin" Value="8,2" />
            </Style>
            <Style x:Key="SmartTable.ButtonsArea" TargetType="StackPanel">
                <Setter Property="DockPanel.Dock" Value="Top" />
                <Setter Property="Margin" Value="8,6" />
                <Setter Property="Height" Value="22" />
                <Setter Property="Orientation" Value="Horizontal" />
                <Setter Property="HorizontalAlignment" Value="Right" />
            </Style>
        </Style.Resources>
    </Style>
    <Style x:Key="SmartTable.Table" TargetType="ListView">
        <Setter Property="Margin" Value="0,0,0,0" />
        <Style.Resources>
            <Style TargetType="TextBlock">
                <Setter Property="Foreground" Value="DimGray" />
            </Style>
            <Style TargetType="GridViewColumnHeader">
                <Setter Property="TextBlock.Foreground" Value="{StaticResource SmartTable.TitleText}" />
            </Style>
        </Style.Resources>
    </Style>
</ResourceDictionary>

И наконец стили данного приложения:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="Header" TargetType="Grid">
        <Style.Resources>
            <Style x:Key="Icon" TargetType="ColumnDefinition">
                <Setter Property="Width" Value="36" />
            </Style>
            <Style x:Key="Commands" TargetType="ColumnDefinition">
                <Setter Property="Width" Value="16" />
            </Style>
        </Style.Resources>
    </Style>
</ResourceDictionary>

Ответы

Ответов пока нет.