question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: x:Bind should be able to reference enums and const

See original GitHub issue

Following good programming practice, I try to define my “magic strings” as constants. If I need to use the same string in both XAML and C#, I can define it in C# as a constant, but there is no way to reference it in the XAML so I end up having to define it again in as a static resource. In WPF this could be partially solved by defining it as a static readonly string and referencing it with {x:Static}, but this is not available in UWP and {StaticResource} does not have the same functionality.

As an example, I’m trying to do this:

<TextBlock Text="{x:Bind SomeProperty, Converter={StaticResource MyConverter}, ConverterParameter=MyCustomFormat}" />

where MyCustomFormat is a string constant defined and used in the code-behind.

Please add the ability to refer to C# constants and static fields in UWP XAML.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
MikeHillbergcommented, Jul 6, 2020

I agree that x:Bind should be able to reference enums and const.

1reaction
MikeHillbergcommented, Jul 1, 2020

@jeremiahmercier-3136, are you saying that WPF’s x:Static and Xaml’s x:Bind both support static, but neither support const?

(I agree with having the feature)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it better to pass a enum class as value or const reference ...
enum class holds an integral value just like a regular enum so you can safely pass it by value without any overhead.
Read more >
TypeScript string enums, and when and how to use them
No matter how much you know about TypeScript enums, this guide covers all the best practices for using string-based enums in production.
Read more >
How To Use Enums in TypeScript
In TypeScript, enums, or enumerated types, are data structures of constant length that hold a set of constant values. Each of these constant...
Read more >
TypeScript: Handbook - Enums
Enums allow a developer to define a set of named constants. Using enums can make it easier to document intent, or create a...
Read more >
Bring enum variants in scope for patterns
So I would propose to make this change at an edition boundary, with rust fix changing any code which uses a variant name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found