feat(InAppNotification): first version of the control

This commit is contained in:
Odonno 2017-07-25 13:36:14 +02:00
Родитель 24ec0c3851
Коммит 24d0431572
10 изменённых файлов: 380 добавлений и 0 удалений

Просмотреть файл

@ -263,6 +263,7 @@
<Content Include="SamplePages\HeaderedTextBlock\HeaderedTextBlock.png" />
<Content Include="SamplePages\ImageCache\ImageEx.png" />
<Content Include="SamplePages\ImageEx\ImageEx.png" />
<Content Include="SamplePages\InAppNotification\InAppNotification.png" />
<Content Include="SamplePages\Incremental Loading Collection\icon.png" />
<Content Include="SamplePages\Light\LightBehavior.png" />
<Content Include="SamplePages\LinkedIn Service\LinkedInLogo.png" />
@ -418,6 +419,9 @@
<Compile Include="SamplePages\BluetoothLEHelper\BluetoothLEHelperPage.xaml.cs">
<DependentUpon>BluetoothLEHelperPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\InAppNotification\InAppNotificationPage.xaml.cs">
<DependentUpon>InAppNotificationPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\Menu\Commands\VsCommands.cs" />
<Compile Include="SamplePages\Menu\MenuPage.xaml.cs">
<DependentUpon>MenuPage.xaml</DependentUpon>
@ -675,6 +679,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="SamplePages\InAppNotification\InAppNotificationPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\Menu\MenuPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 694 B

Просмотреть файл

@ -0,0 +1,28 @@
<Page
x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.InAppNotificationPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel>
<Button x:Name="ShowNotificationWithRandomTextButton"
Content="Show notification with random text"
Click="ShowNotificationWithRandomTextButton_Click" />
<Button x:Name="ShowNotificationWithButtonsButton"
Content="Show notification with buttons"
Click="ShowNotificationWithButtonsButton_Click" />
<Button x:Name="DismissNotificationButton"
Content="Dismiss"
Click="DismissNotificationButton_Click" />
</StackPanel>
<controls:InAppNotification x:Name="ExampleInAppNotification"
Content="This is a test message." />
</Grid>
</Page>

Просмотреть файл

@ -0,0 +1,109 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
public sealed partial class InAppNotificationPage : Page
{
public InAppNotificationPage()
{
InitializeComponent();
}
private void ShowNotificationWithRandomTextButton_Click(object sender, RoutedEventArgs e)
{
var random = new Random();
int result = random.Next(1, 4);
if (result == 1)
{
ExampleInAppNotification.Show("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sollicitudin bibendum enim at tincidunt. Praesent egestas ipsum ligula, nec tincidunt lacus semper non.");
}
if (result == 2)
{
ExampleInAppNotification.Show("Pellentesque in risus eget leo rhoncus ultricies nec id ante.");
}
if (result == 3)
{
ExampleInAppNotification.Show("Sed quis nisi quis nunc condimentum varius id consectetur metus. Duis mauris sapien, commodo eget erat ac, efficitur iaculis magna. Morbi eu velit nec massa pharetra cursus. Fusce non quam egestas leo finibus interdum eu ac massa. Quisque nec justo leo. Aenean scelerisque placerat ultrices. Sed accumsan lorem at arcu commodo tristique.");
}
}
private void ShowNotificationWithButtonsButton_Click(object sender, RoutedEventArgs e)
{
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
// Text part
var textBlock = new TextBlock
{
Text = "Do you like it?",
VerticalAlignment = VerticalAlignment.Center
};
grid.Children.Add(textBlock);
// Buttons part
var stackPanel = new StackPanel
{
Orientation = Orientation.Horizontal,
VerticalAlignment = VerticalAlignment.Center
};
var yesButton = new Button
{
Content = "Yes",
Width = 150,
Height = 30
};
yesButton.Click += YesButton_Click;
stackPanel.Children.Add(yesButton);
var noButton = new Button
{
Content = "No",
Width = 150,
Height = 30,
Margin = new Thickness(10, 0, 0, 0)
};
noButton.Click += NoButton_Click;
stackPanel.Children.Add(noButton);
Grid.SetColumn(stackPanel, 1);
grid.Children.Add(stackPanel);
ExampleInAppNotification.Show(grid);
}
private void YesButton_Click(object sender, RoutedEventArgs e)
{
ExampleInAppNotification.Dismiss();
}
private void NoButton_Click(object sender, RoutedEventArgs e)
{
ExampleInAppNotification.Dismiss();
}
private void DismissNotificationButton_Click(object sender, RoutedEventArgs e)
{
ExampleInAppNotification.Dismiss();
}
}
}

Просмотреть файл

@ -238,6 +238,13 @@
"XamlCodeFile": "Menu.bind",
"Icon": "/SamplePages/Menu/Menu.png",
"DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/UWPCommunityToolkit/dev/docs/controls/Menu.md"
},
{
"Name": "InAppNotification",
"Type": "InAppNotificationPage",
"About": "The In App Notification control offers the ability to show local notifications in your application.",
"CodeUrl": "https://github.com/Microsoft/UWPCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification",
"Icon": "/SamplePages/InAppNotification/InAppNotification.png"
}
]
},

Просмотреть файл

@ -0,0 +1,33 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System;
using Windows.UI.Xaml;
namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// In App Notification defines a control to show local notification in the app.
/// </summary>
public partial class InAppNotification
{
/// <summary>
/// Event raised when the notification is dismissed
/// </summary>
public event EventHandler Dismissed;
private void DismissButton_Click(object sender, RoutedEventArgs e)
{
Dismiss();
}
}
}

Просмотреть файл

@ -0,0 +1,70 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// In App Notification defines a control to show local notification in the app.
/// </summary>
[TemplatePart(Name = "DismissButton", Type = typeof(Button))]
public sealed partial class InAppNotification : ContentControl
{
private Button _dismissButton;
/// <summary>
/// Initializes a new instance of the <see cref="InAppNotification"/> class.
/// </summary>
public InAppNotification()
{
DefaultStyleKey = typeof(InAppNotification);
}
protected override void OnApplyTemplate()
{
if (_dismissButton != null)
{
_dismissButton.Click -= DismissButton_Click;
}
_dismissButton = (Button)GetTemplateChild("DismissButton");
if (_dismissButton != null)
{
_dismissButton.Click += DismissButton_Click;
}
base.OnApplyTemplate();
}
public void Show(string text)
{
Content = text;
Visibility = Visibility.Visible;
}
public void Show(UIElement element)
{
Content = element;
Visibility = Visibility.Visible;
}
public void Dismiss()
{
Visibility = Visibility.Collapsed;
Dismissed?.Invoke(this, EventArgs.Empty);
}
}
}

Просмотреть файл

@ -0,0 +1,117 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.UI.Controls">
<Style x:Key="DismissTextBlockButtonStyle" TargetType="ButtonBase">
<Setter Property="Background" Value="{ThemeResource HyperlinkButtonBackground}" />
<Setter Property="Foreground" Value="{ThemeResource ApplicationForegroundThemeBrush}" />
<Setter Property="MinWidth" Value="0" />
<Setter Property="MinHeight" Value="0" />
<Setter Property="UseSystemFocusVisuals" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ButtonBase">
<Grid Margin="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
<ContentPresenter x:Name="Text"
Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource HyperlinkButtonBackgroundPointerOver}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource HyperlinkButtonBorderBrushPointerOver}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="DarkRed" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource HyperlinkButtonBackgroundPressed}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource HyperlinkButtonBorderBrushPressed}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource HyperlinkButtonForegroundDisabled}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource HyperlinkButtonBackgroundDisabled}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource HyperlinkButtonBorderBrushDisabled}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="local:InAppNotification">
<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundChromeMediumBrush}" />
<Setter Property="Foreground" Value="{ThemeResource ApplicationForegroundThemeBrush}" />
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlBackgroundAccentBrush}" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Bottom" />
<Setter Property="MinHeight" Value="55" />
<Setter Property="FontSize" Value="15" />
<Setter Property="Visibility" Value="Collapsed" />
<Setter Property="Margin" Value="20 0" />
<Setter Property="Padding" Value="25 10" />
<Setter Property="MaxWidth" Value="1200" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:InAppNotification">
<Grid x:Name="RootGrid"
Margin="{TemplateBinding Margin}"
Padding="{TemplateBinding Padding}"
MaxWidth="{TemplateBinding MaxWidth}"
Visibility="{TemplateBinding Visibility}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
HorizontalContentAlignment="Stretch"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
VerticalContentAlignment="Center"
TextWrapping="WrapWholeWords" />
<Button x:Name="DismissButton"
Grid.Column="1"
Margin="10 0 -10 0"
FontSize="12"
Style="{StaticResource DismissTextBlockButtonStyle}"
Content="&#xE894;" FontFamily="Segoe MDL2 Assets"
AutomationProperties.Name="Dismiss" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

Просмотреть файл

@ -55,6 +55,8 @@
<Compile Include="BladeView\BladeView.Properties.cs" />
<Compile Include="Carousel\Carousel.cs" />
<Compile Include="Carousel\CarouselPanel.cs" />
<Compile Include="InAppNotification\InAppNotification.cs" />
<Compile Include="InAppNotification\InAppNotification.Events.cs" />
<Compile Include="Menu\Menu.Events.cs" />
<Compile Include="Menu\Menu.Extensions.cs" />
<Compile Include="Menu\Menu.cs" />
@ -183,6 +185,11 @@
<SubType>Designer</SubType>
<Generator>XamlIntelliSenseFileGenerator</Generator>
</Page>
<Page Include="InAppNotification\InAppNotification.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page>
<Page Include="Menu\Menu.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

Просмотреть файл

@ -23,5 +23,6 @@
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/Carousel/Carousel.xaml" />
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.xaml" />
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/Menu/Menu.xaml" />
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>