Skip to content

[Feature]Adds support for DataTemplateSelectors to InAppNotification.Β #4384

@lighterhy

Description

@lighterhy

Describe the problem this feature would solve

Currently InAppNotification does not support DataTemplateSelector.
Consider the following XAML:

    <ctcontrols:InAppNotification x:Name="InAppNotification" ShowDismissButton="False" StackMode="StackInFront" Style="{ThemeResource MSEdgeNotificationStyle}">
      <ctcontrols:InAppNotification.Resources>
        <DataTemplate x:Key="TextOnly">
        ...
        </DataTemplate>
        <DataTemplate x:Key="CustomContent">
        ...
        </DataTemplate>
        <DataTemplate x:Key="TextWithButtons">
        ...
        </DataTemplate>
        <DataTemplate x:Key="CustomContentWithButtons">
        ...
        </DataTemplate>
      </ctcontrols:InAppNotification.Resources>
      <ctcontrols:InAppNotification.ContentTemplateSelector>
        <ciiwinui:ArgumentKeyTemplateSelector ArgumentKeyName="NotificationTemplateType">
          <ciiwinui:ArgumentKeyTemplateSelector.DataTemplates>
            <StaticResource x:Key="TextOnly" ResourceKey="TextOnly" />
            <StaticResource x:Key="CustomContent" ResourceKey="CustomContent" />
            <StaticResource x:Key="TextWithButtons" ResourceKey="TextWithButtons" />
            <StaticResource x:Key="CustomContentWithButtons" ResourceKey="CustomContentWithButtons" />
          </ciiwinui:ArgumentKeyTemplateSelector.DataTemplates>
        </ciiwinui:ArgumentKeyTemplateSelector>
      </ctcontrols:InAppNotification.ContentTemplateSelector>
    </ctcontrols:InAppNotification>

And when I say:

        dynamic arguments = new ExpandoObject();

        arguments.NotificationTemplateType = "TextOnly";
        arguments.Text = "Notification text comes here.";

        notification.Dismiss();
        notification.Show(arguments);

The template selector ArgumentKeyTemplateSelector does not take any effect and SelectTemplateCore not fired.

Describe the solution

InAppNotification is a great control to show notifications in my app. But I feel difficult to reuse the DataTemplate for same kind of content, or choose different DataTemplate for different content. I think DataTemplateSelector is a good way to resolve this.

Describe alternatives you've considered

InAppNotification.Show may also need to provide an overload like:

void Show(object content, DataTemplate dataTemplate, int duration = 0);

We can be able to choose different templates according to the content we want to show.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request πŸ“¬A request for new changes to improve functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions