Microsoft-ui-xaml: Question: Xaml Design Time Attributes and {x: Bind}

Created on 6 Feb 2020  ·  3Comments  ·  Source: microsoft/microsoft-ui-xaml

Hello,

I’ve searched quite extensively online trying to understand how can we use x:Bind and also have design time data at the same time and the only suggested solutions seem to involve using FallbackValue (e.g. https://stackoverflow.com/questions/31766366/uwp-xbind-and-design-time-data or creating some sort of “design” ViewModel as per https://fast417.blogspot.com/2016/06/uwp-design-preview-with-xbind.html)

A better approach that would require less development effort and also be less invasive (e.g. avoid polluting our ViewModels production code with design time data) would be to support more design time attributes (e.g. Text) similarly for instance to what Android allows via it’s tools attributes (https://developer.android.com/studio/write/tool-attributes)

P.S - I've created a similar ticket on Developer Community but didn't receive any feedback.

Thanks,
Cosmin

area-Tooling feature proposal question team-Markup

Most helpful comment

Indeed @mrlacey's article looks a lot like what I'm looking for.

I'll give it a try. Thanks!

All 3 comments

I had tried porting an older DesignTime Data sample (article here) to current UWP, but soon realized there are a lot more gaps, though some methods still work. I thought I had a thread somewhere on this, but can't remember where now...

I know @mrlacey blogged about this topic as well here.

Indeed @mrlacey's article looks a lot like what I'm looking for.

I'll give it a try. Thanks!

None of the suggested approaches that use x:Bind worked, so writing the following code seems to be the only way of supporting both design-time instances and the x:Bind markup extension. Appears to be quite verbose though.

The reason is that when your XAML page is opened in Visual Studio or Blend for Visual Studio, the imperative code that assigns the DataContext value is never run (in fact, none of your code-behind is executed). The XAML tools do of course parse your markup and instantiate any objects declared in it, but they don't actually instantiate your page's type itself. The result is that you won't see any data in your controls or in the Create Data Binding dialog, and your page will be more challenging to style and to lay out — Sample data on the design surface, and for prototyping @ https://docs.microsoft.com/en-us/windows/uwp/data-binding/displaying-data-in-the-designer

Was this page helpful?
0 / 5 - 0 ratings