gpt4 book ai didi

c# - WPF 设计器代码一直告诉我有错误

转载 作者:太空宇宙 更新时间:2023-11-03 18:43:42 25 4
gpt4 key购买 nike

这是我的表单 XAML 代码。

<Window x:Class="Bail.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns="clr-namespace:Bail"
Title="MainWindow" Height="768" Width="1024" WindowStartupLocation="CenterScreen"
Closing="Window_Closing" ResizeMode="NoResize">
<Grid>
<Grid.Resources>
<src:ListboxMenuItems x:Key="ListboxMenuItems"/>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="185" />
<!-- Or Auto -->
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>


<ListBox Width="150" Margin="0,5,0,10" Grid.Column="0"
ItemsSource="{StaticResource ListboxMenuItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Padding="5,0,5,0" Text="{Binding FirstName}" />
<TextBlock Text="{Binding LastName}" />
<TextBlock Text=", " />
<TextBlock Text="{Binding Address}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>


<Canvas Grid.Column="1" />
</Grid>
</Window>

这里是错误


更正 xmlns:src 后,我得到以下信息警告:

警告 1 ''src' 是未声明的前缀。第 8 行,第 14 位。 XML 无效。 C:\Users\Shayaan Siddiqui\Documents\Bail\Bail\Bail\MainWindow.xaml 8 14 保释金

ListBoxMenuItems 是我用 C# 创建的类。

这是类的代码

//FileName: ListboxMenuItems.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bail
{
public class ListboxMenuItem
{
public String FirstName { get; set; }
public String LastName { get; set; }
public String Address { get; set; }

public ListboxMenuItem(String firstName, String lastName, String address)
{
this.FirstName = firstName;
this.LastName = lastName;
this.Address = address;
}
}

class ListboxMenuItems
{
List<ListboxMenuItem> Items { get; private set; }
public ListboxMenuItems()
{
Items = new List<ListboxMenuItem>();
Items.Add(new ListboxMenuItem("Michael", "Anderberg", "12 North Third Street, Apartment 45"));
Items.Add(new ListboxMenuItem("Chris", "Ashton", "34 West Fifth Street, Apartment 67"));
Items.Add(new ListboxMenuItem("Cassie", "Hicks", "56 East Seventh Street, Apartment 89"));
Items.Add(new ListboxMenuItem("Guido", "Pica", "78 South Ninth Street, Apartment 10"));
}
}
}

最佳答案

xmlns:src="clr-namespace:ListBoxSnippetEx"

您的代码中缺少此行。将 ListBoxSnippetEx 替换为您的项目命名空间。

关于c# - WPF 设计器代码一直告诉我有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6344748/

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