При компиляции WPF проекта в VS ошибка System.IO.IOException: "Не удается найти ресурс "loginwindow.xaml"."
Код по большей части Qwen писал, я как мог пытался исправитить файл, решения не нашел При компиляции ошибка
System.IO.IOException: "Не удается найти ресурс "loginwindow.xaml"."
Строка ошибки:
throw new IOException(SR.Get("UnableToLocateResource", _name));
LoginWindow.xaml
<Window x:Class="Project1.LoginWindow"
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:Project1"
mc:Ignorable="d"
Title="Вход" Height="350" Width="400"
WindowStartupLocation="CenterScreen">
<Grid Margin="20">
<StackPanel VerticalAlignment="Center">
<TextBlock Text="Добро пожаловать!" FontSize="20" FontWeight="Bold"
Margin="0,0,0,20" HorizontalAlignment="Center"/>
<!-- Поле логина с водяным знаком -->
<TextBox Style="{StaticResource WatermarkTextBox}"
Tag="Логин"
Text="{Binding Login, UpdateSourceTrigger=PropertyChanged}"/>
<!-- Поле пароля -->
<Grid Margin="0,5">
<PasswordBox x:Name="PasswordBox"
PasswordChanged="PasswordBox_PasswordChanged"/>
<TextBlock x:Name="passwordWatermark"
Text="Пароль"
Foreground="{StaticResource PlaceholderColor}"
Margin="8,0"
IsHitTestVisible="False"
Visibility="Visible"/>
</Grid>
<Button Content="Войти"
Command="{Binding LoginCommand}"
Height="40" Margin="0,10,0,0"/>
<Button Content="Нет аккаунта? Зарегистрируйтесь!"
Command="{Binding NavigateToRegisterCommand}"
Style="{StaticResource HyperlinkButton}"
Margin="0,15,0,0"/>
</StackPanel>
</Grid>
</Window>
LoginWindow.xaml.cs
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using Project1.ViewModels;
namespace Project1
{
public partial class LoginWindow : Window
{
private readonly string filePath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory, "start.txt");
public LoginWindow()
{
InitializeComponent();
DataContext = new LoginViewModel(this);
}
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
if (DataContext is LoginViewModel viewModel)
{
viewModel.Password = PasswordBox.Password;
}
}
}
}
App.xaml
<Application x:Class="Project1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Project1"
StartupUri="LoginWindow.xaml">
<Application.Resources>
<SolidColorBrush x:Key="BackgroundColor" Color="#F0F8FF"/>
<SolidColorBrush x:Key="PrimaryColor" Color="#87CEFA"/>
<SolidColorBrush x:Key="TextColor" Color="#333333"/>
<SolidColorBrush x:Key="BorderColor" Color="#B0C4DE"/>
<SolidColorBrush x:Key="PlaceholderColor" Color="#A9A9A9"/>
<Style TargetType="TextBox" x:Key="WatermarkTextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="2">
<ScrollViewer x:Name="PART_ContentHost" Margin="5,0"/>
</Border>
<TextBlock x:Name="watermark"
Text="{TemplateBinding Tag}"
Foreground="{StaticResource PlaceholderColor}"
Margin="8,0"
IsHitTestVisible="False"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Visibility="Collapsed"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Text" Value="">
<Setter TargetName="watermark" Property="Visibility" Value="Visible"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter TargetName="watermark" Property="Visibility" Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- Базовый стиль для окон -->
<Style TargetType="Window">
<Setter Property="Background" Value="{StaticResource BackgroundColor}"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontFamily" Value="Segoe UI"/>
</Style>
<!-- Стиль для текстовых полей -->
<Style TargetType="TextBox">
<Setter Property="Margin" Value="0,5"/>
<Setter Property="Padding" Value="8"/>
<Setter Property="BorderBrush" Value="{StaticResource BorderColor}"/>
<Setter Property="Background" Value="White"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Height" Value="32"/>
</Style>
<!-- Стиль для кнопок -->
<Style TargetType="Button">
<Setter Property="Margin" Value="0,10,0,0"/>
<Setter Property="Padding" Value="12,6"/>
<Setter Property="Background" Value="{StaticResource PrimaryColor}"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}"
CornerRadius="4"
Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#6495ED"/>
</Trigger>
</Style.Triggers>
</Style>
<!-- Стиль для гиперссылки -->
<Style TargetType="Button" x:Key="HyperlinkButton">
<Setter Property="Foreground" Value="#4682B4"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<TextBlock Text="{TemplateBinding Content}"
TextDecorations="Underline"
HorizontalAlignment="Center"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="#1E90FF"/>
</Trigger>
</Style.Triggers>
</Style>
</Application.Resources>
</Application>
ResoursePart.cs
using System;
using System.IO;
using System.IO.Packaging;
using System.Resources;
using System.Security;
using System.Windows;
using MS.Internal.Resources;
namespace MS.Internal.AppModel;
internal class ResourcePart : PackagePart
{
private SecurityCriticalDataForSet<ResourceManagerWrapper> _rmWrapper;
private bool _ensureResourceIsCalled;
private string _name;
private object _globalLock = new object();
[SecurityCritical]
public ResourcePart(Package container, Uri uri, string name, ResourceManagerWrapper rmWrapper)
: base(container, uri)
{
if (rmWrapper == null)
{
throw new ArgumentNullException("rmWrapper");
}
_rmWrapper.Value = rmWrapper;
_name = name;
}
[SecurityCritical]
[SecurityTreatAsSafe]
protected override Stream GetStreamCore(FileMode mode, FileAccess access)
{
Stream stream = null;
stream = EnsureResourceLocationSet();
if (stream == null)
{
stream = _rmWrapper.Value.GetStream(_name);
if (stream == null)
{
throw new IOException(SR.Get("UnableToLocateResource", _name));
}
}
ContentType contentType = new ContentType(base.ContentType);
if (MimeTypeMapper.BamlMime.AreTypeAndSubTypeEqual(contentType))
{
BamlStream bamlStream = new BamlStream(stream, _rmWrapper.Value.Assembly);
stream = bamlStream;
}
return stream;
}
protected override string GetContentTypeCore()
{
EnsureResourceLocationSet();
return MimeTypeMapper.GetMimeTypeFromUri(new Uri(_name, UriKind.RelativeOrAbsolute)).ToString();
}
private Stream EnsureResourceLocationSet()
{
Stream stream = null;
lock (_globalLock)
{
if (_ensureResourceIsCalled)
{
return null;
}
_ensureResourceIsCalled = true;
try
{
if (string.Compare(Path.GetExtension(_name), ".baml", StringComparison.OrdinalIgnoreCase) == 0)
{
throw new IOException(SR.Get("UnableToLocateResource", _name));
}
if (string.Compare(Path.GetExtension(_name), ".xaml", StringComparison.OrdinalIgnoreCase) == 0)
{
string name = Path.ChangeExtension(_name, ".baml");
stream = _rmWrapper.Value.GetStream(name);
if (stream != null)
{
_name = name;
return stream;
}
}
}
catch (MissingManifestResourceException)
{
}
}
return null;
}
}