Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!