Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I {x:Bind} to a DataTemplate's root type in UWP?

I have a template that receives a string as its data type:

<DataTemplate x:DataType="System:String">
   <TextBlock Text="{x:Bind}" />
</DataTemplate>

But this binding technique gives me a build error. How can I use {x:Bind} without a path value? I want to bind the string, not a property in the string.

like image 572
Laith Avatar asked Oct 01 '15 02:10

Laith


People also ask

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">

Which of the following template describes the visual structure of a data object?

You typically use a DataTemplate to specify the visual representation of your data.


1 Answers

You actually can do Text="{x:Bind}" without specifying a path. The Designer will complain but it's safe to ignore it.

I think the problem is the way you define the string type. Note in WinRT XAML it now writes as x:String.

So this should work -

<DataTemplate x:Key="GroupTemplate" x:DataType="x:String">
    <TextBlock Text="{x:Bind}" />
</DataTemplate>
like image 127
Justin XL Avatar answered Oct 03 '22 22:10

Justin XL