terminal icon indicating copy to clipboard operation
terminal copied to clipboard

x:Bind not Binding

Open miniksa opened this issue 4 years ago • 7 comments

Per @Austin-Lamb ... We should avoid Binding everywhere we can and use x:Bind instead.

This represents not forgetting about this by tomorrow morning as it popped in my head and reminded me as I tried to sleep.

miniksa avatar Nov 16 '21 07:11 miniksa

protip: find in all files for {Binding . That'll get you: image

7 matches across 5 files

zadjii-msft avatar Nov 16 '21 11:11 zadjii-msft

I was told also that x:Bind is not 100% feature compatible with Binding... but that x:Bind should be strongly preferred wherever it can be used.

miniksa avatar Nov 16 '21 15:11 miniksa

Thanks for filing this, I was meaning to but have been busy. Yeah, {x:Bind} is preferred for performance over {Binding}. x:Bind lives in hotter code in XAML's binary so it will be loaded off disk more quickly, and it is optimized for better CPU performance by not doing as much "Reflection" at runtime (in C++ it's not really reflection, it's IXamlMetadataProvider). Note that x:Bind generates code into your app so it will cause your binaries to grow, but the amount should be marginal for how few bindings Terminal has.

One 'gotcha' with x:Bind (as noted on its docs page here) is that x:Bind defaults to OneTime mode. This can be good for perf (which is why it's the default) but it can be easy to overlook when converting a Binding. You can either manually set the Mode in each x:Bind, or if you know you want to do that for every binding in a tree/file you can use x:DefaultBindMode).

It's been a while since I looked at this, but it would seem that x:Bind may not support ElementName bindings. You may need to check with the owners of bindings in XAML to see if there's a way to do what you're doing there but using x:Bind (perhaps via function bindings, I'm just not sure how you'd do change notifications correctly in a case like biding to the Slider's Value).

Austin-Lamb avatar Nov 16 '21 16:11 Austin-Lamb

Does this still need to be worked on? I

smeet07 avatar Oct 01 '24 05:10 smeet07

Hey! I'd love to work on this issue as my contribution.
Could you please confirm if it's still relevant and assign it to me? 😊

Bhavika42 avatar Mar 19 '25 09:03 Bhavika42

I'd assume that it does need to be worked on ; feel free to get started on it if you'd like. We typically don't actually assign issues, since the Assigned-to field across the repo is usually pretty stale 😕

zadjii-msft avatar Mar 19 '25 10:03 zadjii-msft

I was told also that x:Bind is not 100% feature compatible with Binding... but that x:Bind should be strongly preferred wherever it can be used.

I dont think it supports relative binding and binding to framework elements which based on my cursory search is the only places in the code base not using x:Bind

jamespack avatar May 26 '25 23:05 jamespack