WPF List
I am trying to implement a Listbox in a WPF Application. My Problem is that i can´t add new items bc i do not understand the shit behind the listbox. Can someone help me
40 Replies
It's hard to answer the question "I don't understand the shit". Specific questions are much more likely to get useful responses
What exactly don't you understand?
they previously mentioned using databindings, but no further details are known
$details
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
How can i add items to the list
show your code. specifically the list and what it is bound to
those are not bound
you have no databindings there
yeah i have no idea how to do it
But I asked "are you using data bindings or not"
and you said that you were
but you are not.
my task is to add books with 3 Stages: To be read, in progressed or finished an then the book should go in one of the list
Okay
There are a few ways to do that
You could manually insert and move items around
or have them all point to the same source, but with a "filter" in place
thats significantly harder to implement thou
i have made an enum with the 3 stages
Right.. Please name your enums appropriately :p
ToBeRead
InProgress
Finished
etcand on another Ui you can select the Status
mhm
thats fine.
sorry that it is in german xD
So, you are currently NOT using data bindings. Is this fine and you want to keep not using them, or do you want to use bindings?
i want to use data binding but i am not quite sure how to do it
You don't have to, just fyi.
You can easily do this without bindings.
yeah i know... but my task is to use databinding
Okay, great.
See, if you had just said this from the start, that would be better.
yeah sorry
i am working in a team and thought they had made it already sorry
so, bindings are always relative to the windows "data context"
do you currently have a data context at all? Look at your
<Window ...>
declarationn in the xaml
and also in your public partial class MainWindow : Window
or whatever your window is calledi don´t think so
check the .xaml.cs file too, to make sure
okay
that means your context is the window itself
meaning you could in theory bind something to
books
hereyeah.. i made a class with all the details to a book
okay, those are private fields
you'll want public properties for the bindings
how can i change that?
Do you not know what public vs private is?
and property vs field for that matter
not really
Then uh.. you need to go back and learn that
this is trying to do surgery without knowing what a scalpel is
ok
thanks
you will want to read and understand this (very long) documentation: https://learn.microsoft.com/en-us/dotnet/desktop/wpf/data/?view=netdesktop-7.0#binding-to-collections
Data binding overview - WPF .NET
Learn about the different data sources you can add to your project in Windows Presentation Foundation for .NET. Data sources can be bound to XAML elements to create dynamic apps.
I think this is roughly what you wanted, yes?
pardon the absolutely terrible user interface
yeah
okay, so the way to do that is with a single list and three "collection views"
Stack Overflow
WPF Multiple CollectionView with different filters on same collection
I'm using a an ObservableCollection with two ICollectionView for different filters.
One is for filtering messages by some type, and one is for counting checked messages.
As you can see message fil...
thank you very much