Using Selected Items in WPF to Filter Buses and put the Filtered Buses in a ComboBox
CmbBus should output the name of bus4 after I select matching properties of bus4 but the combo box is still empty. How do I fix this so it will show any bus that matches with the properties I selected. Let me know if you need more details. This is my BusesViewModel code: https://pastebin.com/DfnM7V7B
Pastebin
BusesViewModel.cs - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
53 Replies
$paste
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Please paste there instead of pastebin
BlazeBin - adgzortxniiq
A tool for sharing your source code with the world!
Okay couple of things here
First you raise OnPropertyChanged on
FilteredBuses
, but FilteredBuses
isn't actually changed
Second, why are you making the Buses
prop an ObservableCollection
if you're not binding to it?Sorry I’m new and I’m still not sure how data binding works
I took some of the code in chatgpt😢 sorry
Ill just remove filtered buses? is it not necessary to have it there?
Can you show your xaml file as well 😅 ?
Yesyes
BlazeBin - ukvztomknjtm
A tool for sharing your source code with the world!
My Bus class if you need it🙌
https://paste.mod.gg/fmwawkkkfvna/2
BlazeBin - fmwawkkkfvna
A tool for sharing your source code with the world!
Sorry was away, lemme check them real quick
Alright, you need to change the logic to something like this
Will this be the same for the others?
I'll try this right now
still empty?
Gimme a second to take a look at the code again 😅
OH
Change
MatchingBuses
to a method and change
Yeah
its still empty 😦
is my selected items not matching? or the filter method is not working TT
Are you using CommunityToolkit.MVVM?
i dont remember downloading that
Okay go over to your
BusesViewModel
and hover over ObservableObject
next to it
Under what namespace is it?
Also
Are you 100% sure you're binding to your ViewModel?DigiTrip_App.Core.ObservableObject
not suree
Okay, F12 over it
@s0wi When you run the program does an icon like this show up on the top
Where exactly?
i dont see any symbols like that
The program's window
Okay, can you select a date and check if it changes to red?
omg yes
also time
i was so confused why it turns red earlier 🫠
What does this mean tho?
should I convert something?
No you don't need a converter
You can simply do
Don't bind SelectedItem, bind to SelectedValue on your item source's elemenets
Okk
Why not selectedItem?
Do this for the other control as well
SelectedItems WILL force you to make a converter
i do this to Date also?
not from and to?
Because SelectedItems means bind an item from the ItemSource to a property, your item source has
Bus
objects in them, it can't bind to DateTime or TimeOhhh
From and To bind to their respective types
Ill change them to Selected Value also?
No need, the properties are already of type
BusTerminal
THANK YOU SO MUCH TVT THIS REALLY HELPED
Wait is it important that I put selected value path?
It's important, without it the binding will fail
Are you busy after this? I might add a question here later TvT
I'd probably be busy yeah, you can open another thread or head over at #gui Some amazing people are very active
THANK YOU SO MUCH
np
s0wi#3448
Please help me, I'm confused why it doesn't show up when my other View like cancellation shows up just fine. Can someone help me so that it would show once I click on the Travel History? I would really appreciate who helps. Tell me if you want more details. For now this is the link of the usercontrol and mainwindow.xaml: https://paste.mod.gg/aialvcampztg/0
Embed Type
Link
Quoted by
<@!585888303018934273> from #TextBlock and ListBox is not showing up when I run the program WPF C# (click here)
React with ❌ to remove this embed.