public override DataTemplate SelectTemplate(object item, DependencyObject container) { //FrameworkElement element = container as FrameworkElement; //if (element != null && item != null && item is Task) DIDeviceInfo diDeviceInfo = item as DIDeviceInfo; if (diDeviceInfo != null) { return(_DIDeviceInfoDT); } else { PnPEntityInfo pnpEntityInfo = item as PnPEntityInfo; if (pnpEntityInfo != null) { return(_PnPEntityInfoDT); } } return(null); }
public static void FormatDataIntoRichText(InlineCollection inlines, PnPEntityInfo pnpEntityInfo) { //Run run; inlines.Add( new Run($"Name: {pnpEntityInfo.Name}") { FontWeight = ImportantFontWeight, Foreground = ImportantBrush } ); inlines.Add(new LineBreak()); inlines.Add(new LineBreak()); inlines.Add(new Run($"VID_PID: ") { FontWeight = ImportantFontWeight }); inlines.Add( new Run(pnpEntityInfo.VID_PID.ToString()) { FontWeight = ImportantFontWeight, Foreground = ImportantBrush } ); inlines.Add(new LineBreak()); inlines.Add(new Run($"PID_VID string: ") { FontWeight = ImportantFontWeight }); inlines.Add( new Run(pnpEntityInfo.PID_VIDstring) { FontWeight = ImportantFontWeight, Foreground = ImportantBrush } ); inlines.Add(new LineBreak()); inlines.Add(new LineBreak()); // Device ID formating var deviceID = pnpEntityInfo.DeviceID; /* Dbg * for (int i = 0; i < deviceID.Length; i++) * { * Debug.WriteLine($"{i} {deviceID[i]}"); * }*/ int pidIndex = deviceID.IndexOf(WMI.PIDprefix); int vidIndex = deviceID.IndexOf(WMI.VIDprefix); int igIndex = deviceID.IndexOf(WMI.XInputDeviceIDMarker); int igIDEndIndex = -1; //int[] startIndexes = new int[] { pidIndex, vidIndex, igIndex }; //Array.Sort(startIndexes); var startIndexes = new List <int>(3); if (pidIndex != -1) { startIndexes.Add(pidIndex); } if (vidIndex != -1) { startIndexes.Add(vidIndex); } if (igIndex != -1) { startIndexes.Add(igIndex); igIDEndIndex = deviceID.IndexOf('&', igIndex) - 1; } startIndexes.Sort(); int unimportantChunkStartIndex = 0; //startIndexes[0] - 1; inlines.Add(new Run($"DeviceID: ") { FontWeight = ImportantFontWeight }); foreach (var startIndex in startIndexes) { inlines.Add( new Run( //deviceID.Substring(unimportantChunkStartIndex, startIndex - unimportantChunkStartIndex) deviceID.SubstringR(unimportantChunkStartIndex, startIndex - 1) ) //{ Foreground = _UnimportantBrush } ); if (startIndex == pidIndex || startIndex == vidIndex) { inlines.Add( new Run( deviceID.Substring(startIndex, 8) ) { FontWeight = ImportantFontWeight, Foreground = ImportantBrush } ); unimportantChunkStartIndex = startIndex + 8; } else // igIndex { inlines.Add( new Run( deviceID.SubstringR(startIndex, igIDEndIndex) ) { FontWeight = ImportantFontWeight, Foreground = ImportantBrush } ); //unimportantChunkStartIndex = startIndex + 5; unimportantChunkStartIndex = igIDEndIndex; } } inlines.Add( new Run(deviceID.Substring(unimportantChunkStartIndex + 1)) //{ Foreground = _UnimportantBrush } ); inlines.Add(new LineBreak()); inlines.Add(new Run($"PnPDeviceID: {pnpEntityInfo.PnPDeviceID}")); inlines.Add(new LineBreak()); inlines.Add(new Run($"ClassGUID: {pnpEntityInfo.ClassGUID}")); inlines.Add(new LineBreak()); inlines.Add(new LineBreak()); inlines.Add(new Run($"Description: {pnpEntityInfo.Description}")); //inlines.Add(new LineBreak()); }