I have a ListBox with several items on it (TextBlocks, Images and so on), what I'm trying to do is access an element by it's name at a specific ListBox index.
I know the element name and the index i need to access, in this case I need to change the visibility property of an image control to collapsed.
I've looked at a few examples using VisualTreeHelper
here but they were only to access element by name, not by name and index, which is what i need to do but have not been able to.
Thanks, Bob.
I implemented a small demo to emphasize data binding using MVVM patern. In this example I toggle the
TextBlock
visibility using ShowTextbox property bound to theTextBlock.Visibility
by un/checking theCheckbox
.App.xaml.cs
MainWindow.xaml
MainWindow.cs
MainViewModel.cs
MyModel.cs
ObservableObject.cs
I ended up going about it in a slightly different way, based on the example found here and using the elements' tag property instead, just changing the element from a
TextBlock
to anImage
This way i could bind the element Tag, and use that later on do target the needed items.
Hopefully this helps someone else in the future...