【问题标题】:Error setting datatype for data template x:DataType="local:Data"为数据模板 x:DataType="local:Data" 设置数据类型时出错
【发布时间】:2019-02-07 14:50:26
【问题描述】:

在列表视图 UWP 中为数据模板设置数据类型时,我遇到了这个问题

"严重性代码描述项目文件行抑制状态 错误 XDG0008 名称空间中不存在名称“数据” “使用:数据样本”。

注意:我添加了命名空间但不起作用

xmlns:data="using:datasample"

<ListView x:Name="listView" HorizontalAlignment="Center">
        <ListView.ItemTemplate>
            <DataTemplate x:DataType="data:Datasam">
                <Grid Windows10FallCreatorsUpdate:ColumnSpacing="50">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="2*"/>
                        <ColumnDefinition Width="6*"/>
                        <ColumnDefinition Width="2*"/>
                    </Grid.ColumnDefinitions>
                    <Image Width="20" Height="20" Grid.Column="0" Source="/Assets/Icons/applogo.png"/>
                    <StackPanel Orientation="Vertical" Grid.Column="1">
                        <TextBlock Text="{Binding name}" Foreground="White" FontWeight="Bold"/>
                        <TextBlock Text="{Binding description}"/>
                    </StackPanel>
                    <StackPanel Windows10FallCreatorsUpdate:Spacing="15" Grid.Column="2" Orientation="Vertical">
                        <TextBlock Text="{Binding creatdate}"/>
                        <StackPanel Orientation="Horizontal" Windows10FallCreatorsUpdate:Spacing="10">
                            <Image Width="20" Height="20" Source="/Assets/Icons/applogo.png"/>
                            <Image Width="20" Height="20" Source="/Assets/Icons/applogo.png"/>
                            <Image Width="20" Height="20" Source="/Assets/Icons/applogo.png"/>
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

如何解决。

【问题讨论】:

    标签: uwp uwp-xaml


    【解决方案1】:

    在我的情况下,我在 DataTemplate 的网格内使用了间距,当我删除它时,它可以工作

    <ListView x:Name="listView" HorizontalAlignment="Center">
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="data:Datasam">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="2*"/>
                            <ColumnDefinition Width="6*"/>
                            <ColumnDefinition Width="2*"/>
                        </Grid.ColumnDefinitions>
                        <Image Width="20" Height="20" Grid.Column="0" Source="/Assets/Icons/applogo.png"/>
                        <StackPanel Orientation="Vertical" Grid.Column="1">
                            <TextBlock Text="{Binding name}" Foreground="White" FontWeight="Bold"/>
                            <TextBlock Text="{Binding description}"/>
                        </StackPanel>
                        <StackPanel Grid.Column="2" Orientation="Vertical">
                            <TextBlock Text="{Binding creatdate}"/>
                            <StackPanel Orientation="Horizontal">
                                <Image Width="20" Height="20" Source="/Assets/Icons/applogo.png"/>
                                <Image Width="20" Height="20" Source="/Assets/Icons/applogo.png"/>
                                <Image Width="20" Height="20" Source="/Assets/Icons/applogo.png"/>
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    

    【讨论】:

      【解决方案2】:

      构建整个项目(构建 -> 构建解决方案) 如果它不起作用,请在几分钟后关闭,然后打开您的项目

      如果它不起作用??,请使用“本地”而不是您在上面描述的数据,然后构建您的项目

      【讨论】:

      • 在我的情况下没有任何效果,我已经在下面发布了我的答案
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多