所以,我正在尝试在应用程序中实现一些数据绑定的实践,但我不断收到引用错误,说
“名称SubtopicButton在命名空间中不存在'使用:TestApp.Models'”
也许其他人可以指出我所缺少的东西,但这里是相关的代码片段,所以也许我只是忽略了一些东西。
更新:这是完整的XAML,如果它能够为它提供更多的亮点
<Page
x:Class="TestApp.SubtopicPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:data="using:TestApp.Models"
mc:Ignorable="d">
<Grid Background="{ThemeResource SystemControlForegroundBaseHighBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="125"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" x:Name="Back" Height="100" Width="100" Tapped="{x:Bind backButtonTapped}" HorizontalAlignment="Left" Margin="50,20,0,0" VerticalAlignment="Top" FontSize="40">
<Button.Background>
<ImageBrush ImageSource="Assets/backButton.png"/>
</Button.Background>
</Button>
<GridView ItemsSource="{x:Bind SubtopicButtons}">
<GridView.ItemTemplate>
<DataTemplate x:DataType="data:TestApp.Models.SubtopicButton">
<StackPanel>
<Image Width="300"/>
<TextBlock FontSize="16"/>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
</Page>
然后这是资源管理器视图
然后这里是文件SubtopicButton.cs
namespace TestApp.Models
{
public class SubtopicButton
{
public string SubtopicName { get; set; }
public string Image { get; set; }
}
public class SubtopicButtonManager
{
public static List<SubtopicButton> GetSubtopicButtons()
{
var subtopicButtons = new List<SubtopicButton>();
subtopicButtons.Add(new SubtopicButton { SubtopicName = "Gender Roles", Image = "Assets/femaleMaleSymbol.jpg" });
subtopicButtons.Add(new SubtopicButton { SubtopicName = "Meeting Proceedings", Image = "Assets/femaleMaleSymbol.jpg" });
subtopicButtons.Add(new SubtopicButton { SubtopicName = "Concept of Time", Image = "Assets/femaleMaleSymbol.jpg" });
subtopicButtons.Add(new SubtopicButton { SubtopicName = "Business Ethics", Image = "Assets/femaleMaleSymbol.jpg" });
subtopicButtons.Add(new SubtopicButton { SubtopicName = "Greetings & Personal Reference", Image = "Assets/femaleMaleSymbol.jpg" });
subtopicButtons.Add(new SubtopicButton { SubtopicName = "Cultural Pitfalls", Image = "Assets/femaleMaleSymbol.jpg" });
subtopicButtons.Add(new SubtopicButton { SubtopicName = "Personal Space", Image = "Assets/femaleMaleSymbol.jpg" });
subtopicButtons.Add(new SubtopicButton { SubtopicName = "Negotiation and Ideas of Public Image", Image = "Assets/femaleMaleSymbol.jpg" });
return subtopicButtons;
}
}
}
最后这里是XAML页面背后的代码,其中包含我引用为Item Source的属性SubtopicButtons(类型列表)。
public sealed partial class SubtopicPage : Page
{
private List<SubtopicButton> SubtopicButtons;
public SubtopicPage()
{
this.InitializeComponent();
SubtopicButtons = SubtopicButtonManager.GetSubtopicButtons();
}
所有这一切都说,抛出错误的唯一部分是我在顶部的XAML中包含的部分,但我包括了所有部分,因为我有点不知所措。我没有得到什么?提前感谢你们给予的任何帮助