gpt4 book ai didi

c# - 命名空间中不存在 wpf 资源字典?

转载 作者:行者123 更新时间:2023-11-30 17:41:06 31 4
gpt4 key购买 nike

我正在使用 .net 4.5.2我不知道为什么我的项目继续说资源丢失。我已将我的 mainWindow.xaml 放在一个文件夹中,并重新设置应用程序的路径以定位其位置。真正奇怪的是它在 visual studio 中正确显示,但当我尝试编译它时出错,说项目中不存在“主题”命名空间。

enter image description here

Severity Code Description Project File Line Error CS0234 The type or namespace name 'Themes' does not exist in the namespace 'WpfApplication1' (are you missing an assembly reference?) WpfApplication1 C:\Users\jmartini\Projects\wpf_Styling_4.5.2\WpfApplication1\WpfApplication1\obj\Debug\View\MainWindow.g.i.cs 33

这是我的代码...

MainWindow.xaml

<Window x:Class="WpfApplication1.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:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="200" Width="250"
WindowStartupLocation="CenterScreen">
<DockPanel>
<Button Content="Push It!" Width="70" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</DockPanel>
</Window>

JMStyles.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1.Themes">

<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="15" />
<Setter Property="SnapsToDevicePixels" Value="True" />
</Style>

</ResourceDictionary>

App.xaml

<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
StartupUri="View/MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/JMStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

让它工作的解决方案...我从样式页面中删除了这一行:

xmlns:local="clr-namespace:WpfApplication1.Themes"

原创

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="15" />
<Setter Property="SnapsToDevicePixels" Value="True" />
</Style>

</ResourceDictionary>

最佳答案

我删除了这行代码

xmlns:local="clr-namespace:WpfApplication1.Themes"

从下面的样式页面文件内容...

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1.Themes">

<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="15" />
<Setter Property="SnapsToDevicePixels" Value="True" />
</Style>

</ResourceDictionary>

关于c# - 命名空间中不存在 wpf 资源字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33477705/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com