C
C#ā€¢2w ago
Dan

What is the correct ternary operation here?

I cannot "assign" values in ternary operations?
No description
28 Replies
Servator
Servatorā€¢2w ago
ternary for assignment not comparison but if you put inside () it could work i think put right side of == in ()
leowest
leowestā€¢2w ago
Application.Current.MainWindow.WindowState = _windowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
Application.Current.MainWindow.WindowState = _windowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
Servator
Servatorā€¢2w ago
Also you are complicating Just use switch expression
leowest
leowestā€¢2w ago
to me it looks like you're trying to assing the wrong thing no?
Servator
Servatorā€¢2w ago
When i look to your code i dont get what you are trying to do
Dan
DanOPā€¢2w ago
yeah
Dan
DanOPā€¢2w ago
No description
leowest
leowestā€¢2w ago
šŸ‘†
Servator
Servatorā€¢2w ago
Application.Current.MainWindow.WindowState = WindowState.Minimize; ?
Servator
Servatorā€¢2w ago
No description
Servator
Servatorā€¢2w ago
Yeah But command is maximize command Yeah that's what im trying to explain
leowest
leowestā€¢2w ago
It would be a MaximizeRestoreWindowCommand as is anyway the problem is that his code and ternary are wrong like I pointed out
Dan
DanOPā€¢2w ago
I guess this would be better?
No description
Dan
DanOPā€¢2w ago
more readable and they are separate a command for each button
leowest
leowestā€¢2w ago
you could do that yes, and since the button is named Minimized and the other Maximize it would make more sense
Dan
DanOPā€¢2w ago
yep, great šŸ‘
Servator
Servatorā€¢2w ago
Also what's the type of "o" ? Maybe you can use that too
Dan
DanOPā€¢2w ago
object
Servator
Servatorā€¢2w ago
It's probably boxed to object nvm just dont care then šŸ˜„
Dan
DanOPā€¢2w ago
hmm
leowest
leowestā€¢2w ago
you should look into using CommunityToolkit.Mvvm it will reduce and simplify a lot of your code
Dan
DanOPā€¢2w ago
how can i check not .Equals?
Servator
Servatorā€¢2w ago
You could put "!" start of it or simply "is not x"
Dan
DanOPā€¢2w ago
Is this valid?
No description
leowest
leowestā€¢2w ago
we would need to know what o is first, u would have to breakpoint and check its insides since you're using a RelayCommand it might depend how it was setup and what its passing over
Servator
Servatorā€¢2w ago
Looks like it's an action but im not so sure
BlyZe
BlyZeā€¢2w ago
You could just do this:
Application.Current.MainWindow.WindowState = WindowState.Maximized;
Application.Current.MainWindow.WindowState = WindowState.Maximized;
The check doesn't make much sense there
Servator
Servatorā€¢2w ago
Problem is Command is MaximizeWindowCommand so it should minimize
Want results from more Discord servers?
Add your server