0

所以,我正在尝试在应用程序中实现一些数据绑定,但我不断收到一个参考错误,说

“名称 SubtopicButton 不存在于命名空间 'using: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 页面背后的代码,其中包括我引用为项目源的属性 SubtopicButtons(类型列表)。

    public sealed partial class SubtopicPage : Page
    {

         private List<SubtopicButton> SubtopicButtons;



         public SubtopicPage()
         {
             this.InitializeComponent();
             SubtopicButtons = SubtopicButtonManager.GetSubtopicButtons();
         }

话虽如此,唯一引发错误的部分是我在顶部的 XAML 中包含的部分,但我将其全部包含在内,因为我有点不知所措。我没有得到什么?提前感谢你们可以提供的任何帮助

4

0 回答 0