C
C#2y ago
Dawnbomb

What WPF Treeview trigger happens after a user selects something?

In winforms treeviews have a trigger called AfterSelect that occurs...after the user selects something. It doesn't trigger if something is unselected, only if a new thing is selected. In WPF, AfterSelect doesn't exist. i looked through then and found SelectedItemChanged but it triggers when something is unselected. This causes my program to error / crash because i am using the name of the selected item as part of a filepath search. Theres a lot of triggers and a lot of google to figure out what one triggers only after a user selects something, so i thought i would just make a post asking if anyone knows what trigger occurs only after a user selects something in a treeview.
55 Replies
sibber
sibber2y ago
then check if something is selected before doing whatever also dont use the designer it generates unreadable code that relies on margins for layout so you dont get responsiveness
Dawnbomb
Dawnbomb2y ago
"the designer"? huh?
sibber
sibber2y ago
visual drag and drop thing its called something designer iirc
Dawnbomb
Dawnbomb2y ago
yeah visual designer i uh, really only want to use a visual designer using anything else is so awful and slow
sibber
sibber2y ago
slow?
Dawnbomb
Dawnbomb2y ago
it would take way longer for the same result
sibber
sibber2y ago
oh slow to develop
Dawnbomb
Dawnbomb2y ago
yes also, im not sure what you mean by " margins for layout so you dont get responsiveness"
sibber
sibber2y ago
the designer is also not accurate, it can be off by few (or more than a few) pixels
Dawnbomb
Dawnbomb2y ago
whats unresponsive about it?
sibber
sibber2y ago
it means when you resize the window control dont move/scale like they should
Dawnbomb
Dawnbomb2y ago
i noticed this, it seems to only happen with WPF not with winforms
sibber
sibber2y ago
yeah
Dawnbomb
Dawnbomb2y ago
i assume i'll find an answer as to why at a later time and fix it
sibber
sibber2y ago
winforms desginer is fine
Dawnbomb
Dawnbomb2y ago
but current understanding is it has something to do with scaling and star mode
sibber
sibber2y ago
the answer is that its bad and microsoft doesnt update it anymore so it will always be like this but you shouldnt need it anyway learning xaml will be super worth it
Dawnbomb
Dawnbomb2y ago
well, to my knowledge, there is no current visual builder thats better
sibber
sibber2y ago
once youre used it youll be faster than using the designer
Dawnbomb
Dawnbomb2y ago
i shopped around, found nothing just outdated or unfinished crap
sibber
sibber2y ago
yes because writing xaml will always be superior there is no point in making one
Dawnbomb
Dawnbomb2y ago
telling beginners to just be experts and do expert tier design, is not a real answer.
sibber
sibber2y ago
im not doing that
Dawnbomb
Dawnbomb2y ago
you kind of are actually you explicitly are
sibber
sibber2y ago
im telling beginners to learn more so they can do what they want more easily sorry if that came out condescending
Dawnbomb
Dawnbomb2y ago
Hey there mr beginner, why don't you just learn to code in multiple languages and build programs from scratch with no coding knowledge. Ah yes, why didn't i think of that. so 'simple'
sibber
sibber2y ago
xaml isnt a programming language its just for layouts similar to html
Dawnbomb
Dawnbomb2y ago
whatever you want to be fancy and call it, its a language of some kind
sibber
sibber2y ago
it is a language of some kind but its made to make things easier anyway you dont have to learn right now im just saying your life will be easier if you write xaml instead of using the designer
Dawnbomb
Dawnbomb2y ago
anyway, how can i do this...? The entire point is i don't know what trigger to use. I'm asking how to check it.
sibber
sibber2y ago
the same event just check if the selected item is null if it is, return (or do whatever idk) btw xaml isnt just for wpf
Dawnbomb
Dawnbomb2y ago
hmmm, thats a good idea i suppose :0
sibber
sibber2y ago
its used by the vast majority of .net gui frameworks
Dawnbomb
Dawnbomb2y ago
i know but so long as you wanna talk about it xaml will always be terrible for all beginners by basically just existing
sibber
sibber2y ago
everything is terrible for beginners
Dawnbomb
Dawnbomb2y ago
as another language one needs to learn ontop of their primary language
sibber
sibber2y ago
until they learn it again, its not a programming language
Dawnbomb
Dawnbomb2y ago
the coding industry just going "fuck beginners" is dumb as hell
sibber
sibber2y ago
its much easier to learn than a programming language i dont think its going that way
Dawnbomb
Dawnbomb2y ago
but it's also entirely unnecessary
sibber
sibber2y ago
its not
Dawnbomb
Dawnbomb2y ago
well, we don't have any good replacements for winforms it is...
sibber
sibber2y ago
we do, its wpf
Dawnbomb
Dawnbomb2y ago
wpf has xaml
sibber
sibber2y ago
yes thats a good thing
Dawnbomb
Dawnbomb2y ago
and its terrible for beginners its a bad thing
sibber
sibber2y ago
its harder to learn yes but it will be worth it
Dawnbomb
Dawnbomb2y ago
and that makes people quit people quitting isn't worth it
sibber
sibber2y ago
thats why some people recommend starting out with winforms then moving to wpf
Dawnbomb
Dawnbomb2y ago
Yeah, but in order to start with a pure visual builder, we kind of need a new one to exist that didn't end development 2 decades ago
sibber
sibber2y ago
xaml isnt completely non visual xaml hot reload is a thing it lets you see changes you make in xaml, in real time, while the app is running so you know exactly how it will look like, in the actual app
Dawnbomb
Dawnbomb2y ago
anyway il try a if null
sibber
sibber2y ago
btw do you have nullable reference types enabled? it a feature than warns you about stuff like this but youll have to explicitly specify in the declaration whether you want the type to be nullable
Dawnbomb
Dawnbomb2y ago
well it worked i don't know why i didn't think of that probably due to wanting less lines of code so bad i forgot to think about adding more code
sibber
sibber2y ago
yeah more code != bad readable code == good