private void PropertyChanged_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == SelectedItemBindingPath) { var selected = BindingSource.GetType().GetProperty(SelectedItemBindingPath).GetValue(BindingSource); if (SelectedObject != selected && ((IEnumerable)DataContext).Cast <IListInput>().Any(obj => obj == selected)) { listBox.SelectedItem = selected; SelectedObject = selected; } } }
private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { SelectedItem.Children.Clear(); SelectedObject = null; if (e.AddedItems.Count != 0) { var temp = new Property("選択オブジェクト", e.AddedItems[0]); SelectedObject = e.AddedItems[0]; SelectedItem.Children.Add(temp); } if (SelectedItemBindingPath != null && BindingSource.GetType().GetProperty(SelectedItemBindingPath).GetValue(BindingSource) != SelectedObject) { BindingSource.GetType().GetProperty(SelectedItemBindingPath).SetValue(BindingSource, SelectedObject); } }
private void Dialog_Click(object sender, RoutedEventArgs e) { Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog openFileDialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog(); openFileDialog.InitialDirectory = ""; openFileDialog.IsFolderPicker = true; openFileDialog.RestoreDirectory = true; var result = openFileDialog.ShowDialog(new WindowInteropHelper(Window.GetWindow(this)).Handle); if (result == Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult.Ok) { Path.Text = openFileDialog.FileName + "\\"; } if (RootPathBinding != null) { var rootPath = (string)BindingSource.GetType().GetProperties().Cast <PropertyInfo>() .First(obj => obj.GetCustomAttribute(typeof(InspectorModel.RootPathBindingAttribute)) is InspectorModel.RootPathBindingAttribute bindingAttribute && bindingAttribute.Name == RootPathBinding) .GetValue(BindingSource); Path.Text = InspectorModel.Path.GetRelativePath(Path.Text, RootPathBinding); } }