foreach (var item in this.listBox.Items)
{
var container = this.listBox.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;
if (container != null)
{
VisualStateManager.GoToState(container, "Highlighted", true);
}
}if (container != null)
{
VisualStateManager.GoToState(container, "Highlighted", true);
}
As you can see, in container element, you will receive the ListBoxItem (or the container that you are using). This is a very simple operation in comparison with some other that you can find by web where you may read that you need to use VisualTreeHelper or navigate among elements until find the container or some other things.
No hay comentarios:
Publicar un comentario