C
C#•6mo ago
Dan

What is the correct ternary operation here?

I cannot "assign" values in ternary operations?
No description
28 Replies
DeliBey
DeliBey•6mo ago
ternary for assignment not comparison but if you put inside () it could work i think put right side of == in ()
leowest
leowest•6mo ago
Application.Current.MainWindow.WindowState = _windowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
Application.Current.MainWindow.WindowState = _windowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
DeliBey
DeliBey•6mo ago
Also you are complicating Just use switch expression
leowest
leowest•6mo ago
to me it looks like you're trying to assing the wrong thing no?
DeliBey
DeliBey•6mo ago
When i look to your code i dont get what you are trying to do
Dan
DanOP•6mo ago
yeah
Dan
DanOP•6mo ago
No description
leowest
leowest•6mo ago
šŸ‘†
DeliBey
DeliBey•6mo ago
Application.Current.MainWindow.WindowState = WindowState.Minimize; ?
DeliBey
DeliBey•6mo ago
No description
DeliBey
DeliBey•6mo ago
Yeah But command is maximize command Yeah that's what im trying to explain
leowest
leowest•6mo 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•6mo ago
I guess this would be better?
No description
Dan
DanOP•6mo ago
more readable and they are separate a command for each button
leowest
leowest•6mo ago
you could do that yes, and since the button is named Minimized and the other Maximize it would make more sense
Dan
DanOP•6mo ago
yep, great šŸ‘
DeliBey
DeliBey•6mo ago
Also what's the type of "o" ? Maybe you can use that too
Dan
DanOP•6mo ago
object
DeliBey
DeliBey•6mo ago
It's probably boxed to object nvm just dont care then šŸ˜„
Dan
DanOP•6mo ago
hmm
leowest
leowest•6mo ago
you should look into using CommunityToolkit.Mvvm it will reduce and simplify a lot of your code
Dan
DanOP•6mo ago
how can i check not .Equals?
DeliBey
DeliBey•6mo ago
You could put "!" start of it or simply "is not x"
Dan
DanOP•6mo ago
Is this valid?
No description
leowest
leowest•6mo 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
DeliBey
DeliBey•6mo ago
Looks like it's an action but im not so sure
BlyZe
BlyZe•6mo 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
DeliBey
DeliBey•6mo ago
Problem is Command is MaximizeWindowCommand so it should minimize

Did you find this page helpful?