Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

310
Visualizações
Using Sample Data saved as XAML, at Design Time in UWP

I am reading this article and trying to use a sample data for ListView to display the data at the design time.
However, I cannot make it, and am seeing an error saying that it cannot build the DataContext in the ListView at the highlighted part below.

d:DataContext="{d:DesignData SampleData.xaml}"

Visual Studio 2019 16.9.1

The files are as below. These have been saved in one folder in flat.

Could you help me to know the appropriate way of such using of sample data?

MainPage.xaml:

<Page
    x:Class="App1.MainPage"
    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"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" 
    d:DesignWidth="459" d:DesignHeight="262">
    <Grid>
        <ListView d:DataContext="{d:DesignData SampleData.xaml}"
                  ItemsSource="{Binding Mode=OneWay}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBox Text="-- " />
                        <TextBox Text="{Binding Name}" />
                        <TextBox Text="{Binding Age}" />
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Page>

SampleData.xaml (marked as DesignData for the build action):

<sample:PersonCollection
    xmlns:sample="using:App1">
    <sample:Person Name="John Doe" Age="20" />
    <sample:Person Name="Jane Doe" Age="30" />
</sample:PersonCollection>

Person.cs:

namespace App1 {
    public class Person  {
        public string Name { get; set; }
        public int Age { get; set; }

        public Person() {
        }
    }
}

PersonCollection.cs:

using System.Collections.ObjectModel;

namespace App1{
    public class PersonCollection : ObservableCollection<Person> {
        public PersonCollection(): base(){
        }
    }
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Using Sample Data saved as XAML, at Design Time in UWP

I'm afraid you can't use Xaml design data for UWP app, derive from this document, One good option is the Create Sample Data from Class feature in Blend for Visual Studio. You can find that command on one of the buttons at the top of the Data panel. Unfortunately,

The Data panel in Blend is supported only for projects that target .NET Framework. It's not supported for UWP projects or projects that target .NET Core.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda