Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UWP X:Bind and Design Time Data

is it possible to use x:bind and design time data in uwp apps?

e.g if I had a textbox that used x:bind to bind to a property on viewmodel in the code behind, should that property's value appear in the textbox in the designer?

is there a way of achieving this?

cheers

Johnny

like image 943
Johnny Spittle Avatar asked Aug 01 '15 21:08

Johnny Spittle


People also ask

What is data binding in UWP?

Data binding is the process that establishes a connection between the UI layer with our Data Layer. So when you change your Data your GUI is updated and vice versa.

What is x Bind?

x-bind allows you to set HTML attributes on elements based on the result of JavaScript expressions. For example, here's a component where we will use x-bind to set the placeholder value of an input. <div x-data="{ placeholder: 'Type here...' }"> <input type="text" x-bind:placeholder="placeholder">

Does UWP use MVVM?

Many of the other UWP app samples also use a basic MVVM architecture, and the Traffic App sample includes both code-behind and MVVM versions, with notes describing the MVVM conversion.

How does data binding work in WPF?

Data binding is a mechanism in WPF applications that provides a simple and easy way for Windows Runtime apps to display and interact with data. In this mechanism, the management of data is entirely separated from the way data. Data binding allows the flow of data between UI elements and data object on user interface.


1 Answers

x:Bind doesn't support design-time data yet. Maybe it never will given it's designed for compile-time bindings to boost performance (I wish it would though).

For simple UI testing purposes, I would add a FallbackValue to the binding expression to force the designer to show me some dummy text. However, don't forget to remove it once you are done with the design.

<TextBlock Text="{x:Bind MyMoney, FallbackValue='$10,000,000'}" />

Update

Now it's easier with the new design-time data support.

<TextBlock Text="{x:Bind MyMoney}" d:Text="$10,000,000" />

Read more from here.

like image 106
Justin XL Avatar answered Oct 27 '22 00:10

Justin XL