应用程序返回“[ClassName] 在命名空间中不存在”,即使它在同一命名空间中明确声明

问题描述 投票:0回答:1

我正在使用 Windows95-WPF GitHub 项目中的代码,但是即使是这样,我真的似乎无法在这里找到问题。

我尝试更改名称空间,尝试验证所有文件中是否正确引用了名称空间,

local:
引用了相同的名称空间,等等。 如果有人尝试编译,就会出现其他错误,因为它依赖于 Windows95.dll,但我不关心其他错误,就是这个让我发疯。

正如你所看到的,命名空间似乎在任何地方都被正确引用...我正在运行 .net 5 顺便说一句

这是MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RadioSim
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

这是 MainWindow.xaml(第 94 行是错误所在)

<Window x:Class="RadioSim.MainWindow"
        xmlns="*****"
        xmlns:x="*****"
        xmlns:d="*****"
        xmlns:mc="*****"
        xmlns:local="clr-namespace:RadioSim"
        xmlns:windows95="clr-namespace:Windows95;assembly=Windows95"
        mc:Ignorable="d"
        Title="MainWindow"
        Height="450"
        Width="800"
        Background="#C3C3C3"
        ResizeMode="NoResize"
        Icon="Images/windows.ico">
    <Grid>
        <StackPanel Orientation="Horizontal"
                    Margin="20,12,0,0"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Top">
            <TextBlock Text="Welcome to"
                       FontFamily="Times New Roman"
                       FontSize="28"
                       FontWeight="SemiBold"
                       TextOptions.TextRenderingMode="Aliased"
                       TextOptions.TextFormattingMode="Display"
                       TextOptions.TextHintingMode="Fixed"
                       SnapsToDevicePixels="True" />

            <TextBlock Text="Windows"
                       FontFamily="Arial"
                       FontSize="28"
                       FontWeight="Black"
                       Margin="6,0,0,0"
                       TextOptions.TextRenderingMode="Aliased"
                       TextOptions.TextFormattingMode="Display"
                       TextOptions.TextHintingMode="Fixed"
                       SnapsToDevicePixels="True" />

            <TextBlock Text="95"
                       x:Name="WindowsVersionTextBlock"
                       FontFamily="Arial"
                       FontSize="28"
                       Margin="2,0,0,0"
                       TextOptions.TextRenderingMode="Aliased"
                       TextOptions.TextFormattingMode="Display"
                       TextOptions.TextHintingMode="Fixed"
                       SnapsToDevicePixels="True"
                       Foreground="White" />
        </StackPanel>

        <StackPanel Margin="0,48,16,0"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Top">
            <Button Width="115"
                    Height="23"
                    Margin="0,0,0,7"
                    Content="What's New" />

            <Button Width="115"
                    Height="23"
                    Margin="0,0,0,7"
                    Content="Online Registration"
                    Click="OnlineRegistration_Click" />

            <Button Width="115"
                    Height="23"
                    Margin="0,0,0,7"
                    Content="Next Tip"
                    Click="NextTip_Click" />
        </StackPanel>

        <Button Width="115"
                Height="23"
                Margin="0,0,16,16"
                HorizontalAlignment="Right"
                VerticalAlignment="Bottom"
                Content="Close"
                Click="CloseButton_Click" />

        <Rectangle Stroke="#828282"
                   Width="115"
                   Height="1"
                   VerticalAlignment="Bottom"
                   HorizontalAlignment="Right"
                   Margin="0,0,16,51" />

        <Rectangle Stroke="#FFFFFF"
                   Width="115"
                   Height="1"
                   VerticalAlignment="Bottom"
                   HorizontalAlignment="Right"
                   Margin="0,0,16,50" />
        
        <local:TipBox HorizontalAlignment="Left"
                      VerticalAlignment="Top"
                      Margin="20,48,0,0"
                      Width="360"
                      Height="160"
                      x:Name="MainTipBox">
            <local:TipBox.TipText>
                You can change this text by placing a file named 'tips.txt' near the program executable. It's a JSON list.
            </local:TipBox.TipText>
        </local:TipBox>

        <CheckBox Content="Show this Welcome Screen next time you start Windows"
                  HorizontalAlignment="Left"
                  Margin="20,0,0,19"
                  IsChecked="True"
                  IsEnabled="False"
                  VerticalAlignment="Bottom" />
    </Grid>
</Window>

这是 TipBox .xaml

<UserControl x:Class="RadioSim.TipBox"
             xmlns="*****"
             xmlns:x="*****"
             xmlns:mc="*****" 
             xmlns:d="*****" 
             xmlns:local="clr-namespace:RadioSim"
             mc:Ignorable="d" 
             d:DesignHeight="152" d:DesignWidth="328"
             Name="Control">
    <Grid Background="#FFFFFF">
        <Border Background="Transparent"
                BorderThickness="1,1,0,0"
                VerticalAlignment="Stretch"
                HorizontalAlignment="Stretch"
                BorderBrush="#828282" />
        
        <Border Background="Transparent"
                BorderThickness="0,0,1,1"
                Margin="0,1,0,0"
                VerticalAlignment="Stretch"
                HorizontalAlignment="Stretch"
                BorderBrush="White" />
        <Grid Background="#20FFFF00" Margin="1">
            <StackPanel>
                <StackPanel Orientation="Horizontal"
                        Margin="28,20,0,0"
                        VerticalAlignment="Top"
                        HorizontalAlignment="Left">
                    <Image Source="Images/TipIcon.png"
                   Width="23"
                   Height="32"
                   SnapsToDevicePixels="True"
                   HorizontalAlignment="Left"
                   VerticalAlignment="Top"
                   RenderOptions.BitmapScalingMode="NearestNeighbor" />

                    <TextBlock FontFamily="Arial"
                           FontWeight="Bold"
                           FontSize="12"
                           Text="Did you know..."
                           Margin="18,6,0,0"
                           TextOptions.TextRenderingMode="Aliased"
                           TextOptions.TextFormattingMode="Display" />
                </StackPanel>
                
                <TextBlock x:Name="TooltipText"
                           Margin="69,0,40,0"
                           FontFamily="Arial"
                           TextWrapping="Wrap"
                           xml:space="preserve"
                           Text="{Binding ElementName=Control, Path=TipText}"
                           TextOptions.TextRenderingMode="Aliased"
                           TextOptions.TextFormattingMode="Display" />
            </StackPanel>

            
        </Grid>
    </Grid>
</UserControl>

最后,这是 TipBox.xaml.cs 文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RadioSim
{
    /// <summary>
    /// Interaction logic for TipBox.xaml
    /// </summary>
    public partial class TipBox : UserControl
    {
        public static readonly DependencyProperty TipTextProperty = DependencyProperty.Register("TipText", typeof(string), typeof(TipBox), new PropertyMetadata(string.Empty));

        public string TipText
        {
            get { return (string) GetValue(TipTextProperty); }
            set { SetValue(TipTextProperty, value); }
        }

        public TipBox()
        {
            InitializeComponent();
        }
    }
}

OBS:我删除了 XAML 中的链接,因为垃圾邮件过滤器很烦人

c# wpf .net-core
1个回答
0
投票

这似乎也是我经常遇到的问题。 就我而言,通常可以重建项目/解决方案。因此,在您的 IDE 中,只需转到“构建”,然后单击“重建”

© www.soinside.com 2019 - 2024. All rights reserved.