Почему в Visual Studio отображается сообщение об ошибке Windows. Ресурсы не найдены в окне типа? - PullRequest
0 голосов
/ 01 февраля 2020

Я новичок в приложениях WPF. Я создал приложение WPF и хочу использовать главную страницу в своем приложении. Внутри области Window я хочу объявить Window.Resources, но он дает две ошибки: 1- член 'Resources' не распознан или недоступен.
2- присоединяемое свойство 'Resources' не найдено в типе ' Окно'. Где проблема?

Вот мой код XAML:

<Window x:Class="ArmsPosition.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:ArmsPosition"
        mc:Ignorable="d"
        Loaded="Window_Loaded"
        Closing="Window_Closing"        
        WindowState="Normal"
        Title="Arms Positions" Height="560" Width="800" MinHeight="560" MinWidth="800" MaxHeight="560" MaxWidth="800">
    <Grid>
        <Window.Resources>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="FontFamily" Value="Segoe UI"/>
                <Setter Property="FontSize" Value="20"/>
                <Setter Property="Foreground" Value="#FF999999"/>
            </Style>
        </Window.Resources>

    </Grid>
</Window>  

1 Ответ

1 голос
/ 01 февраля 2020

Это потому, что вы используете Windows.Resource в элементе Grid. Resource является прямым дочерним свойством элемента Window.

<Window x:Class="ArmsPosition.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:ArmsPosition"
        mc:Ignorable="d"
        Loaded="Window_Loaded"
        Closing="Window_Closing"        
        WindowState="Normal"
        Title="Arms Positions" Height="560" Width="800" MinHeight="560" MinWidth="800" MaxHeight="560" MaxWidth="800">
    <Window.Resources>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="FontFamily" Value="Segoe UI"/>
            <Setter Property="FontSize" Value="20"/>
            <Setter Property="Foreground" Value="#FF999999"/>
        </Style>
    </Window.Resources>
    <Grid>
        <!--SOME CONTROLS HERE-->
    </Grid>
</Window>  
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...