private void Prev_Executed(object sender, ExecutedRoutedEventArgs e) { PdfSearchItem next = null; TreeViewItem node = null; var current = trvResult?.SelectedItem; if (current is TreeViewItem) { node = GetPrev(current as TreeViewItem); next = node.Items[node.Items.Count - 1] as PdfSearchItem; } else if (current is PdfSearchItem) { var item = current as PdfSearchItem; var father = item.Father; var id = father.IndexOf(item); var t = trvResult.ItemContainerGenerator.Items.First(n => (n as TreeViewItem)?.ItemsSource == father) as TreeViewItem; if (id > 0) { next = father[id - 1] as PdfSearchItem; node = t; } else { node = GetPrev(t); next = node?.Items[node.Items.Count - 1] as PdfSearchItem; } } ((Control)node.ItemContainerGenerator.ContainerFromItem(next))?.Focus(); }
private async void trvResult_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { try { Debug.WriteLine(e.NewValue); PdfSearchItem pdf = e.NewValue as PdfSearchItem; if (pdf == null) { return; } try { await LoadPdf(pdf.PdfFile); } catch (Exception ex) { Debug.Fail(ex.ToString()); } } catch (Exception ex) { Trace.Fail(ex.ToString()); } }