Hey everyone,
I'm wrecking my brain in how to best handle getting this string through a MVVM pattern, which I'm quite new at. C# also isn't my strong point so it could be a very easy solution, I have no idea. English also isn't my first langue, but I'm trying my best.
What I'm trying to do is to get a string attached to a listbox selected item via my class, without ever specifying it in a element in my xaml.
I, for example, have several labels that show the details of a selected listbox item, like so :
Content="{Binding SelectedItem.UploadDate, ElementName=LBController}"
This works amazing and I'm happy with the result.
There's also another value stored inside the connected table with a string property. This property is used for functions within my application.
Ideally I would store this string inside the application outside of an element. There's really no need to let the user see it inside a label or textbox. I'd much rather that my viewmodel immediately picks up the selected listbox value, without ever storing it inside a label or such
I already have it defined inside my viewmodel, like so.
public string CurrentXMLListboxValue { get; set; }
But how do I get the value from my listbox? I dont want to store it(CurrentXMLListboxValue) inside of a label or textbox, I want it to immediately give the value without relying on such an item. Preferably through the listbox. Is this possible following MVVM structure?
What I have tried:
I honestly have no idea if what I want to do is possible. Storing the value inside a label or textbox only to have the viewmodel read that is not my preffered method of going about it, as I do not want the value to be visible. (Neither is an invisible label or textbox, for speed reasons).
My listbox does have a binding for a selected ID, but I'm not sure if that would be of any help.
<ListBox x:Name="LBController" Grid.Column="1" HorizontalAlignment="Left" Grid.RowSpan="6" Grid.Row="1"
ItemsSource ="{Binding AllControllers, UpdateSourceTrigger=PropertyChanged}" SelectedValue="{Binding SelectedControllerID}"
SelectedValuePath="Id" DisplayMemberPath="Name" >
</ListBox>