Пример #1
0
        private void ButtonSendToast_Click(object sender, RoutedEventArgs e)
        {
            // In a real app, these would be initialized with actual data
            string title           = "Andrew Bares";
            string content         = "Cannot wait to try your UWP app!";
            var    logoOverrideUri = new Uri("https://picsum.photos/48?image=883");

            // Construct the content21
            var contentBuilder = new ToastContentBuilder()
                                 .AddToastActivationInfo("app-defined-string", ToastActivationType.Foreground)
                                 .AddText(title)
                                 .AddText(content)
                                 // Profile (app logo override) image
                                 .AddAppLogoOverride(logoOverrideUri, ToastGenericAppLogoCrop.Circle);

            // If we're running on Desktop before Version 1511, do NOT include custom audio
            // since it was not supported until Version 1511, and would result in a silent toast.

            var supportsCustomAudio = !(AnalyticsInfo.VersionInfo.DeviceFamily.Equals("Windows.Desktop") &&
                                        !ApiInformation.IsApiContractPresent(
                                            "Windows.Foundation.UniversalApiContract", 2));

            if (supportsCustomAudio)
            {
                contentBuilder.AddAudio(new Uri("ms-appx:///Assets/Audio/CustomToastAudio.m4a"));
            }

            // Send the toast
            contentBuilder.Show();
        }
Пример #2
0
        public void AddAudioTest_WithAudioUriOnly_ReturnSelfWithCustomAudioAdded()
        {
            // Arrange
            Uri testAudioUriSrc = new Uri("C:/justatesturi.mp3");

            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder.AddAudio(testAudioUriSrc);

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual(testAudioUriSrc.OriginalString, builder.Content.Audio.Src.OriginalString);
        }
Пример #3
0
        public void AddAudioTest_WithAudioObject_ReturnSelfWithCustomAudioAdded()
        {
            // Arrange
            var audio = new ToastAudio()
            {
                Silent = true
            };

            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder.AddAudio(audio);

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreSame(audio, builder.Content.Audio);
        }
Пример #4
0
        public void AddAudioTest_WithFullArgs_ReturnSelfWithCustomAudioAddedWithAllOptionsSet()
        {
            // Arrange
            Uri  testAudioUriSrc      = new Uri("C:/justatesturi.mp3");
            bool testToastAudioLoop   = true;
            bool testToastAudioSilent = true;

            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder.AddAudio(testAudioUriSrc, testToastAudioLoop, testToastAudioSilent);

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual(testAudioUriSrc.OriginalString, builder.Content.Audio.Src.OriginalString);
            Assert.AreEqual(testToastAudioLoop, builder.Content.Audio.Loop);
            Assert.AreEqual(testToastAudioSilent, builder.Content.Audio.Silent);
        }
Пример #5
0
 public IUwpExtension AddAudio(Uri src, bool?loop = null, bool?silent = null)
 {
     tbc.AddAudio(src, loop, silent);
     return(this);
 }