para cualquier persona que todavía tiene problemas con esto, yo era capaz de solucionar este problema al ignorar el evento cambiado primera selección y el uso de un hilo básicamente repetir la llamada. Esto es lo que terminé haciendo:
private int _hackyfix = 0;
private void OnMediaSelectionChanged(object sender, SelectionChangedEventArgs e)
{
//HACKYFIX:Hacky workaround for an api issue
//Microsoft's api for getting item controls for the flipview item fail on the very first media selection change for some reason. Basically we ignore the
//first media selection changed event but spawn a thread to redo the ignored selection changed, hopefully allowing time for whatever is going on
//with the api to get things sorted out so we can call the "ContainerFromItem" function and actually get the control we need I ignore the event twice just in case but I think you can get away with ignoring only the first one.
if (_hackyfix == 0 || _hackyfix == 1)
{
_hackyfix++;
Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>
{
OnMediaSelectionChanged(sender, e);
});
}
//END OF HACKY FIX//Actual code you need to run goes here}
EDITAR 10/29/2014: En realidad ni siquiera es necesario el código despachador hilo. Puedes configurar lo que necesites para anular el evento de la primera selección modificada y luego regresar al evento para que los eventos futuros funcionen como se espera.
private int _hackyfix = 0;
private void OnMediaSelectionChanged(object sender, SelectionChangedEventArgs e)
{
//HACKYFIX: Daniel note: Very hacky workaround for an api issue
//Microsoft's api for getting item controls for the flipview item fail on the very first media selection change for some reason. Basically we ignore the
//first media selection changed event but spawn a thread to redo the ignored selection changed, hopefully allowing time for whatever is going on
//with the api to get things sorted out so we can call the "ContainerFromItem" function and actually get the control we need
if (_hackyfix == 0)
{
_hackyfix++;
/*
Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>
{
OnMediaSelectionChanged(sender, e);
});*/
return;
}
//END OF HACKY FIX
//Your selection_changed code here
}
¿No puede simplemente iterar a través de Items, que sería una colección de solo lectura (pero su contenido no sería de solo lectura)? –
Lo intenté también. El uso de .ContainerFromIndex() también devuelve null. –
[Comprobar el siguiente enlace para obtener la respuesta] [1] [1]: http://stackoverflow.com/questions/10591391/why-itemcontainergenerator-containerfromindex-returns-null-and-how- to-avoid-th/27792628 # 27792628 –