uwpuwp-xamldesignerxbind

UWP no Element Content or Text when Binding with x:Bind


I am very new to UWP and binding, but I believe I am figuring it out and making progress. However, I am unsure if I am doing something wrong when using x:bind in design mode. When I bind to my View Model, it works perfectly when the application is running, but when in design mode the element content, be it TextBlock text, Button text, etc., goes to empty. This makes designing very difficult as I don't know where everything actually is on the page and the element sizes tend to go down to nothing, so they can hardly be clicked on or moved.

Microsoft says here "...But if you're using {x:Bind} then your bindings at least show placeholder values on the design surface (even for items controls), so you don't have quite the same need for sample data." But I don't get any placeholder data for anything.

Here is a typical line for an element:

<TextBlock x:Name="ItemCountLabel" Text="{x:Bind Path=ViewModel.ItemCountText, Mode=OneWay}"/>

I have tried a few things to make something work, like using Fallback value, but I can't seem to find a way of having placeholder text. Is there such a thing? Am I doing something wrong? Or is this just the way it is.

Any help appreciated.


Solution

  • UWP no Element Content or Text when Binding with x:Bind

    I'm afraid you can't display design data with x:Bind, Because x:Bind doesn't support design-time data. And the binding objects created by {x:Bind} and {Binding} are largely functionally equivalent. But {x:Bind} executes special-purpose code, which it generates at compile-time that means FallbackValue(Specifies a value to display when the source or path cannot be resolved.) property can't forecast if the binding path is resolved.

    For the scenario, We suggest use Binding and FallbackValue in design time like the following.

    <TextBlock Foreground="Red" x:Name="ItemCountLabel" Text="{Binding ItemCountText,FallbackValue='Test Value', Mode=OneWay}"/>