A Better Way to Deal with Complex Bindings in XAML

  Рет қаралды 1,895

SingletonSean

SingletonSean

Күн бұрын

Пікірлер: 25
@SirBenJamin_
@SirBenJamin_ 5 ай бұрын
I hate converters, I only really use the visibility ones. The people I work with will go out of their way to write really specific converters JUST so they don't have to "pollute" their viewmodel. So we have a library of these wacky converters with really long names. For me, I think its daft. A viewmodel is specifically there to sit between the model and the View to make binding easier! .. so I will have all sorts of stuff on that sucker. Its much easier to code, debug and maintain ... and it performs better.
@SingletonSean
@SingletonSean 5 ай бұрын
Totally agree!! The worst is when you run into a converter that references and casts some sort of domain object or view model 😬
@TheTigerus
@TheTigerus 5 ай бұрын
you can also use Switch Case and return something like -1, 0, 1 (or enum, or w/e) saving you 2 properties to update
@SingletonSean
@SingletonSean 5 ай бұрын
True! I'd prefer to use an enum with that approach, but then writing data triggers against enum values is kinda funky cause you have to import the enum into XAML
@dasfahrer8187
@dasfahrer8187 5 ай бұрын
Clever. Bravo. 👏
@solvedplus858
@solvedplus858 3 ай бұрын
many thanks for your awesome tutorial i hope to use in your tutorial the native MVVM without any plugins, this will be more easy for the beginners to follow
@billymartin6497
@billymartin6497 5 ай бұрын
Wouldn't it be cleaner to have a number to color converter? Also, is there any way to have a converter to return a tuple? If so, how do I write the xaml to know which tuple value to use?
@SingletonSean
@SingletonSean 5 ай бұрын
That would work but I like to stay away from converters if I can. In this context, the ranges that classify the colors as good, medium, or bad could be considered domain logic. I consider converters to be part of the view layer. I like to keep domain logic at the view model layer or above, preferably in the model layer.
@billymartin6497
@billymartin6497 5 ай бұрын
@@SingletonSean Thanks for your speedy reply. Is the tuple converter possible?
@ivandrofly
@ivandrofly 4 ай бұрын
Thanks InstanceSean :)
@haroldpepete
@haroldpepete 5 ай бұрын
nice approach and the view looks cleaner, that would be a good video, when muldidatatrigger is worth it, use cases and more tips in your style? i mean "the clever style"
@SingletonSean
@SingletonSean 5 ай бұрын
Thanks! I'd almost always prefer using this view model approach instead of a multi data-trigger. A good use case for multi data-triggers is, of course, when you don't have a view model. An example of this would be custom components or styling, such as only applying a style to a list view item when it's not selected and being hovered.
@mehdi_aghaei_
@mehdi_aghaei_ 5 ай бұрын
Is there any way that we could just use one function which set the rate?
@SingletonSean
@SingletonSean 5 ай бұрын
Probably! As for this demo, a single property that could return a good, medium, or bad enum would also work. However, sometimes I don't like working with enums in XAML.
@paulgarcia-r6b
@paulgarcia-r6b 5 ай бұрын
An interesting library you can use is DXBinding. You can write C# code in XAML itself
@hellfim
@hellfim 5 ай бұрын
Wouldn't it be actually better and cleaner to handle this stuff in code-behind?
@lexpsd
@lexpsd 5 ай бұрын
agree, i would probably create a private method that returns a SolidColorBrush and a string, then use properties to transfer those values into xaml; long xaml is the worst nightmare if you forget about it for a week, and then will try to acknowledge it once again
@SirBenJamin_
@SirBenJamin_ 5 ай бұрын
@@hellfim this assumes you have a code behind file.
@burger_flipper
@burger_flipper 5 ай бұрын
In this example it's using MVVM so code behind is absolutely forbidden
@lexpsd
@lexpsd 4 ай бұрын
@@SirBenJamin_ no bro, i mean in the viewmodel file
@hellfim
@hellfim 4 ай бұрын
@@burger_flipper code-beind is not forbidden in MVVM. It's forbidden to put business logic there, but I believe using it for complex visual behaviours is actually OK.
@ChadMerlin-d8m
@ChadMerlin-d8m 2 ай бұрын
O'Reilly Extension
@ConradCeleste-t6z
@ConradCeleste-t6z 2 ай бұрын
Westley Drive
@LouiseHugh-c6s
@LouiseHugh-c6s 2 ай бұрын
Pollich Points
The View Model Lifecycle in .NET MAUI
4:37
SingletonSean
Рет қаралды 1 М.
Components For Styles (w/ .NET MAUI)
15:26
SingletonSean
Рет қаралды 998
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
Building a .NET MAUI Application in 7 Days
26:59
SingletonSean
Рет қаралды 2,3 М.
How I Launched A Website That Generated $3.98 In Revenue
18:56
SingletonSean
Рет қаралды 1,6 М.
Why SingletonSean?
5:39
SingletonSean
Рет қаралды 1,3 М.
Realtime updates with next.js, socket.io and a redis publisher
16:14
How To Actually Achieve Your Goals in 2025 (Evidence-Based)
15:15
Connect Your .NET MAUI Application to a Database
18:16
SingletonSean
Рет қаралды 3,2 М.
Google’s Quantum Chip: Did We Just Tap Into Parallel Universes?
9:34
The Most Wonderful Type of Tests
18:30
SingletonSean
Рет қаралды 1,3 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 728 М.
Tween (Technique of the Week)
2:27
Flutter
Рет қаралды 56 М.