diff options
Diffstat (limited to 'Software/Visual_Studio/StubsUtils/Notifications.Wpf/NotificationTemplateSelector.cs')
| -rw-r--r-- | Software/Visual_Studio/StubsUtils/Notifications.Wpf/NotificationTemplateSelector.cs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Software/Visual_Studio/StubsUtils/Notifications.Wpf/NotificationTemplateSelector.cs b/Software/Visual_Studio/StubsUtils/Notifications.Wpf/NotificationTemplateSelector.cs new file mode 100644 index 000000000..aab11a7fa --- /dev/null +++ b/Software/Visual_Studio/StubsUtils/Notifications.Wpf/NotificationTemplateSelector.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace Notifications.Wpf +{ + public class NotificationTemplateSelector : DataTemplateSelector + { + private DataTemplate _defaultStringTemplate; + private DataTemplate _defaultNotificationTemplate; + + private void GetTemplatesFromResources(FrameworkElement container) + { + _defaultStringTemplate = + container?.FindResource("DefaultStringTemplate") as DataTemplate; + _defaultNotificationTemplate = + container?.FindResource("DefaultNotificationTemplate") as DataTemplate; + } + + public override DataTemplate SelectTemplate(object item, DependencyObject container) + { + if (_defaultStringTemplate == null && _defaultNotificationTemplate == null) + { + GetTemplatesFromResources((FrameworkElement)container); + } + + if (item is string) + { + return _defaultStringTemplate; + } + if (item is NotificationContent) + { + return _defaultNotificationTemplate; + } + + return base.SelectTemplate(item, container); + + } + } +}
\ No newline at end of file |
