private Process ChooseProcess(string desc, bool fShow32BitOnly = true) { Process procChosen = null; var q = from proc in Process.GetProcesses() orderby proc.ProcessName where fShow32BitOnly?ProcessType(proc) == "32" : true select new { proc.Id, proc.ProcessName, proc.MainWindowTitle, proc.WorkingSet64, proc.PrivateMemorySize64, Is64 = ProcessType(proc), _proc = proc }; var brPanel = new BrowsePanel(q, new[] { 40, 220, 400 }); var w = new Window { Content = brPanel, Title = desc }; brPanel.BrowseList.MouseDoubleClick += (o, e) => { w.Close(); }; brPanel.BrowseList.KeyUp += (o, e) => { if (e.Key == System.Windows.Input.Key.Return) { w.Close(); } }; w.Closed += (o, e) => { var p = brPanel.BrowseList.SelectedItem; if (p != null) { var proc = TypeDescriptor.GetProperties(p)["_proc"].GetValue(p) as Process; if (!fShow32BitOnly || ProcessType(proc) == "32") { procChosen = proc; } } }; w.ShowDialog(); return(procChosen); }
readonly string _baseTypeName = string.Empty; // includes "_" public BrowseList(IEnumerable query, BrowsePanel browPanel) { this._colWidths = browPanel._colWidths; this.Margin = new System.Windows.Thickness(8); this.ItemsSource = query; var gridvw = new GridView(); this.View = gridvw; var ienum = query.GetType().GetInterface(typeof(IEnumerable <>).FullName); var members = ienum.GetGenericArguments()[0].GetMembers().Where(m => m.MemberType == System.Reflection.MemberTypes.Property); foreach (var mbr in members) { //if (mbr.DeclaringType == typeof(EntityObject)) // if using Entity framework, filter out EntityKey, etc. //{ // continue; //} var dataType = mbr as System.Reflection.PropertyInfo; var colType = dataType.PropertyType.Name; if (mbr.Name.StartsWith("_")) { _baseType = dataType.PropertyType; _baseTypeName = mbr.Name; continue; } GridViewColumn gridcol = null; if (mbr.Name.StartsWith("_x")) // == "Request" || mbr.Name == "Reply" || mbr.Name == "xmlData") { var methodName = string.Format("get_{0}", mbr.Name); // like "get_Request" or "get_Response" var enumerator = query.GetEnumerator(); var fLoopDone = false; while (!fLoopDone) { if (enumerator.MoveNext()) { var currentRecord = enumerator.Current; var currentRecType = currentRecord.GetType(); var msgObj = currentRecType.InvokeMember(methodName, BindingFlags.InvokeMethod, null, currentRecord, null); if (msgObj != null) { var msgObjType = msgObj.GetType(); var msgObjTypeProps = msgObjType.GetProperties(); foreach (var prop in msgObjTypeProps) { AddAColumn(gridvw, prop.Name, mbr.Name); } fLoopDone = true; } } else { fLoopDone = true; } } } else { switch (colType) { case "XmlReader": { gridcol = new GridViewColumn(); var colheader = new GridViewColumnHeader() { Content = mbr.Name }; gridcol.Header = colheader; colheader.Click += new RoutedEventHandler(Colheader_Click); gridvw.Columns.Add(gridcol); } break; default: { AddAColumn(gridvw, mbr.Name, bindingObjectName: null); } break; } } } // now create a style for the items var style = new Style(typeof(ListViewItem)); style.Setters.Add(new Setter(ForegroundProperty, Brushes.Blue)); // style.Setters.Add(new Setter(HorizontalContentAlignmentProperty, HorizontalAlignment.Stretch)); var trig = new Trigger() { Property = IsSelectedProperty,// if Selected, use a different color Value = true }; trig.Setters.Add(new Setter(ForegroundProperty, Brushes.Red)); trig.Setters.Add(new Setter(BackgroundProperty, Brushes.Cyan)); style.Triggers.Add(trig); this.ItemContainerStyle = style; this.ContextMenu = new ContextMenu(); this.ContextMenu.AddMenuItem(On_CtxMenu, "_Copy", "Copy selected items to clipboard"); this.ContextMenu.AddMenuItem(On_CtxMenu, "Export to E_xcel", "Create a temp file of selected items in CSV format. In Excel, select all data, Data->TextToColumns to invoke Wizard if needed"); this.ContextMenu.AddMenuItem(On_CtxMenu, "Export to _Notepad", "Create a temp file of selected items in TXT format"); }