DataContext and DesignData - File not found

In my current layout, I want some data to be visible in the design view, so I read about DataContext and DesignData, and I can't use them correctly.

My MainPage.xaml starts as follows:

<phone:PhoneApplicationPage x:Class="AppStalker.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" shell:SystemTray.IsVisible="True" d:DataContext="{d:DesignData Source=./SampleData/SampleData.xml}"> 

My application compiles without warnings / errors, and I can see the data in the emulator. In any case, after creating the solution, VS 2012 complains that it cannot find C:\path\to\project\AppName\SampleData\SampleData.xml

I triple checked that I have no typos, and I also changed xml to xaml without effect. I also checked three times that the directory and file are displayed in the solution view.

Now it becomes interesting: if I change the path to Source=./App.xaml , it will not complain. If I change it to the MainPage.xaml link, it complains about some errors in the file. If I transfer my SampleData.xml to the same root directory as App.xaml , it still refuses to find them ...

I also changed the file assembly action to Resource , Embedded Resource , DesignData , but nothing changed.

I basically follow this LongListSelector Pass

Any ideas?

+4
source share
1 answer

file must be Resource

If you want to put the file in the root directory of the project; besides App.xaml , just write:

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

and if you want to put it in a folder in your project:

 d:DataContext="{d:DesignData SampleData/SampleFoodData.xml}" 

and this is the same as:

 d:DataContext="{d:DesignData Source=SampleData/SampleFoodData.xml}" 
+1
source

Source: https://habr.com/ru/post/1484860/


All Articles