找不到命名空间前缀 src

Namespace prefix src not found

当输入在 https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.combobox?view=netframework-4.8 找到的一些 XAML 代码时,src: 会抛出错误。有谁知道为什么或有解决方法吗?

<Grid.Resources>
    <src:IEvents x:Key="myIEvents"/>
</Grid.Resources>

Visual Studio 错误:XDG0006 命名空间前缀 "src" 未定义。

注意:我修改了用 Grid 替换 StackPanel 的示例。

这是更新后的 XAML 代码片段:

<Window x:Class="Task_Logger.Window1"
    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:src="clr-namespace:Task_Logger"
    mc:Ignorable="d"

    Title="Idle Time Category" Height="246" Width="376">
    <Grid>
        <Grid.Resources>
            <src:IEvents x:Key="myIEvents"/>
        </Grid.Resources>
        <ComboBox ItemsSource="{StaticResource myIEvents}" 
              HorizontalAlignment="Left" Height="37" Margin="31,20,0,0" 
              VerticalAlignment="Top" Width="311" Name="comboBox1" />
        <TextBlock Text="{Binding ElementName=comboBox1, Path=SelectedItem}"/>

这是.cs文件中的class

namespace Task_Logger
    class iEvents : ObservableCollection<string>
    {
        public iEvents()
        {
            Add("Clog -­ Resin Pot Valves");
            Add("Clog -­ MVP Valves");
            .
            .

IEvents 好像是自定义类型。您需要将其导入页面顶部。 src: 是占位符,或者,本地定义的命名空间别名。

您的页面顶部很可能需要这样的内容:

<Page x:Class="Project.Pages.Page"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 

  <!-- here is your src definition -->
  xmlns:src="clr-namespace:Something.Namespace.WhereIEventIsDefined"/>