применение установленного стиля окна к окну - PullRequest
0 голосов
/ 31 октября 2019

Я определил пользовательский шаблон элемента управления Windows внутри Libraries \ WindowsTemplates:

 <ControlTemplate x:Key="DefaultWindowTemplate" TargetType="{x:Type Window}">
    <Border BorderBrush="Red" BorderThickness="2">
    <Grid Margin="3 3 3 3 " Width="auto" Height="auto">
        <Grid.RowDefinitions>
            <RowDefinition Height="75"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="75"/>
        </Grid.RowDefinitions>

        <UniformGrid Rows="1" Columns="1" Height="75" HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Row="0" >
            <Rectangle  Stretch="Fill" Fill="{StaticResource SteelBrush_Vert}" Stroke="Black" RenderTransformOrigin="0.5,0.5"/>
        </UniformGrid>

    </Grid>
        </Border>
    </ControlTemplate>

Я ссылался на ControlTemplate в App.xaml:

 <ResourceDictionary x:Key="WindowTemplates">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Libraries/WindowsTemplates.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

Я пытаюсь использовать шаблонв моем окне:

Window x:Class="QCast.Windows.RawMatEntry"
    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:QCast.Windows"
    mc:Ignorable="d"
    Title="RawMatEntry" Height="450" Width="800"
    Template="{DynamicResource DefaultWindowTemplate}">

И все же я получаю сообщение об ошибке, что ресурс не может быть решен. Чего мне не хватает?

Весь мой app.xaml выглядит так:

<Application x:Class="QCast.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:QCast"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <Style TargetType="DataGridCell">
        <Setter Property="TextBlock.FontSize" Value="14"/>
        <Setter Property="Height" Value="50"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridCell}">
                    <Border Background="{TemplateBinding Background}">
                        <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ResourceDictionary x:Key="MyDictionaries">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="SteelBrush.xaml"/>
            <ResourceDictionary Source="FullSteel.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

    <ResourceDictionary x:Key="LEDs">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/MindFusion.Gauges.Wpf;component/Themes/Leds.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

    <ResourceDictionary x:Key="WindowTemplates">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Libraries/WindowsTemplates.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

    <ResourceDictionary x:Key="ControlTemplates">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/QCast;component/Libraries/ControlStyles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

</Application.Resources>

1 Ответ

1 голос
/ 31 октября 2019

Поместите все свои ResourceDictionary в собственность ResourceDictionary из Application.Resources:

<Application.Resources>
    <Style TargetType="DataGridCell">
        <Setter Property="TextBlock.FontSize" Value="14"/>
        <Setter Property="Height" Value="50"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridCell}">
                    <Border Background="{TemplateBinding Background}">
                        <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="SteelBrush.xaml"/>
            <ResourceDictionary Source="FullSteel.xaml"/>
            <ResourceDictionary Source="/MindFusion.Gauges.Wpf;component/Themes/Leds.xaml" />
            <ResourceDictionary Source="Libraries/WindowsTemplates.xaml" />
            <ResourceDictionary Source="/QCast;component/Libraries/ControlStyles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

</Application.Resources>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...