private void Scenes_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListBox listBox = sender as ListBox; int index; if (listBox.Items.Count < 1) { return; } if (listBox.SelectedItem == null) { index = 0; } else { index = listBox.SelectedIndex; } string scenePath = (listBox.Items[index] as ListBoxItem).DataContext as string; CreateLayout.showScene(this.myContainer, scenePath); AttributeLayout.InitSceneAttributeLayout(this, myContainer); }