In this section we go over the steps needed to enable you to use your own custom controls as design-time controls, a new capability available to customers using Visual Studio 2019 version 16.8 or later. This feature by default works only with platform controls and properties. Use design-time data with custom types and properties To use the system:String type, make sure you include The benefit here is that you can bind your controls to a design-time static version of your model. xmlns:models="clr-namespace:Cities.Models" To use the class in XAML, you must import the namespace in the root node. For example, public properties of a City data object can be constructed as design-time data.
You can also create an array of data objects. This previous example shows a ListView with three TextBlocks in the XAML Designer. Xmlns:system="clr-namespace:System assembly=mscorlib in your XAML header. The XAML Designer displays what is in that array in your ListView at design time. You can use this feature to create an inline design-time data ItemSource or Items. However, they're difficult to visualize without any data. ListViews are a popular way to display data in your Desktop app. The image in this example must exist in the solution. You can then show that image in the XAML Designer at design time: Add the image you want to show in the XAML Designer to your project. You can set a design-time Source for images that are bound to the page or loaded in dynamically. All d: attributes and controls will be ignored during runtime. Use this method to put a placeholder in for a custom control or to try out different controls. In this example, the button only appears at design time. You can even add it to the control itself. NET Core control, like colors, font sizes, and spacing. You can use d: with attributes for any UWP or WPF. Instead, it shows "Name!" where the TextBlock will have real data at runtime. In this example, without d:Text, the XAML Designer would show nothing for the TextBlock. To get started, add the following lines of code to the header of your XAML document if they aren't already present: xmlns:d=""Īfter adding the namespaces, you can put d: in front of any attribute or control to show it only in the XAML Designer but not at runtime.įor example, you can add text to a TextBlock that usually has data bound to it. If you are using Xamarin.Forms, see Xamarin.Forms Design Time Data Design Time Data basicsĭesign-time data is mock data you set to make your controls easier to visualize in the XAML Designer.