C
C#12mo ago
Matze

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
canton7
canton712mo ago
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?
Pobiega
Pobiega12mo ago
they previously mentioned using databindings, but no further details are known $details
MODiX
MODiX12mo ago
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)
Matze
MatzeOP12mo ago
How can i add items to the list
Pobiega
Pobiega12mo ago
show your code. specifically the list and what it is bound to
Matze
MatzeOP12mo ago
Pobiega
Pobiega12mo ago
those are not bound you have no databindings there
Matze
MatzeOP12mo ago
yeah i have no idea how to do it
Pobiega
Pobiega12mo ago
But I asked "are you using data bindings or not" and you said that you were but you are not.
Matze
MatzeOP12mo ago
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
Pobiega
Pobiega12mo ago
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
Matze
MatzeOP12mo ago
i have made an enum with the 3 stages
Pobiega
Pobiega12mo ago
Right.. Please name your enums appropriately :p ToBeRead InProgress Finished etc
Matze
MatzeOP12mo ago
and on another Ui you can select the Status
Pobiega
Pobiega12mo ago
mhm thats fine.
Matze
MatzeOP12mo ago
sorry that it is in german xD
Pobiega
Pobiega12mo ago
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?
Matze
MatzeOP12mo ago
i want to use data binding but i am not quite sure how to do it
Pobiega
Pobiega12mo ago
You don't have to, just fyi. You can easily do this without bindings.
Matze
MatzeOP12mo ago
yeah i know... but my task is to use databinding
Pobiega
Pobiega12mo ago
Okay, great. See, if you had just said this from the start, that would be better.
Matze
MatzeOP12mo ago
yeah sorry i am working in a team and thought they had made it already sorry
Pobiega
Pobiega12mo ago
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 called
Matze
MatzeOP12mo ago
i don´t think so
Pobiega
Pobiega12mo ago
check the .xaml.cs file too, to make sure
Matze
MatzeOP12mo ago
Pobiega
Pobiega12mo ago
okay that means your context is the window itself meaning you could in theory bind something to books here
Matze
MatzeOP12mo ago
yeah.. i made a class with all the details to a book
Pobiega
Pobiega12mo ago
okay, those are private fields you'll want public properties for the bindings
Matze
MatzeOP12mo ago
how can i change that?
Pobiega
Pobiega12mo ago
Do you not know what public vs private is? and property vs field for that matter
Matze
MatzeOP12mo ago
not really
Pobiega
Pobiega12mo ago
Then uh.. you need to go back and learn that this is trying to do surgery without knowing what a scalpel is
Matze
MatzeOP12mo ago
ok thanks
Pobiega
Pobiega12mo ago
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.
Pobiega
Pobiega12mo ago
I think this is roughly what you wanted, yes? pardon the absolutely terrible user interface
Matze
MatzeOP12mo ago
yeah
Pobiega
Pobiega12mo ago
okay, so the way to do that is with a single list and three "collection views"
Pobiega
Pobiega12mo ago
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...
Matze
MatzeOP12mo ago
thank you very much
Want results from more Discord servers?
Add your server