public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (!(container is FrameworkElement element)) { return(null); } if (!(item is StatusViewerItem listItem)) { return(null); } StatusReportItem.SeverityCode severity = listItem.Data.Severity; switch (severity) { case StatusReportItem.SeverityCode.None: // these are incorrectly initialized ConfigManager.LogManager.LogError( $"received status report item with invalid severity: {listItem.Data.Severity} '{listItem.Data.Status}'; implementation error"); // render using Error template severity = StatusReportItem.SeverityCode.Error; break; case StatusReportItem.SeverityCode.Info: break; case StatusReportItem.SeverityCode.Warning: break; case StatusReportItem.SeverityCode.Error: break; // ReSharper disable once RedundantEmptySwitchSection // new cases are explicitly allowed to have resources with matching names default: break; } return(element.FindResource(severity.ToString()) as DataTemplate); }
/// <summary> /// Instead of a setter for the corresponding string, we use this method to /// ensure the underlying enum can be renamed and otherwise changed safely. /// </summary> /// <param name="code"></param> public void SetStatus(StatusReportItem.SeverityCode code) { SetValue(StatusProperty, code.ToString()); switch (code) { case StatusReportItem.SeverityCode.None: StatusNarrative = "This component is not reporting any status."; break; case StatusReportItem.SeverityCode.Info: StatusNarrative = "This component is configured correctly."; break; case StatusReportItem.SeverityCode.Warning: StatusNarrative = "This component is reporting warnings that should be corrected."; break; case StatusReportItem.SeverityCode.Error: StatusNarrative = "This component is reporting errors and requires attention."; break; } }