private async void DisplayTextButton_Click(object sender, RoutedEventArgs e)
        {
            string text = "Hello from UWP";

            var position = new Point(0, 0);

            if (CenterCheckBox.IsChecked.Value)
            {
                var length = text.Length;
                if (length < lineDisplay.DefaultWindow.SizeInCharacters.Width)
                {
                    position.X = ((int)lineDisplay.DefaultWindow.SizeInCharacters.Width - length) / 2;
                }
            }

            LineDisplayTextAttribute attribute = LineDisplayTextAttribute.Normal;

            if (BlinkCheckBox.IsChecked.Value)
            {
                attribute = LineDisplayTextAttribute.Blink;
            }

            if (await lineDisplay.DefaultWindow.TryClearTextAsync() &&
                await lineDisplay.DefaultWindow.TryDisplayTextAsync(text, attribute, position))
            {
                rootPage.NotifyUser("Text displayed successfully", NotifyType.StatusMessage);
            }
            else
            {
                // We probably lost our claim.
                rootPage.NotifyUser("Unable to display text", NotifyType.ErrorMessage);
            }
        }
示例#2
0
        private async void DisplayTextButton_Click(object sender, RoutedEventArgs e)
        {
            string text = "Hello from UWP";

            using (ClaimedLineDisplay lineDisplay = await ClaimedLineDisplay.FromIdAsync(rootPage.LineDisplayId))
            {
                if (lineDisplay != null)
                {
                    var position = new Point(0, 0);
                    if (CenterCheckBox.IsChecked.Value)
                    {
                        var length = text.Length;
                        if (length < lineDisplay.DefaultWindow.SizeInCharacters.Width)
                        {
                            position.X = ((int)lineDisplay.DefaultWindow.SizeInCharacters.Width - length) / 2;
                        }
                    }

                    LineDisplayTextAttribute attribute = LineDisplayTextAttribute.Normal;

                    // If blinking is requested, verify that the device supports blinking.
                    if (BlinkCheckBox.IsChecked.Value)
                    {
                        if (lineDisplay.Capabilities.CanBlink == LineDisplayTextAttributeGranularity.NotSupported)
                        {
                            BlinkNotSupportedText.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            // Device supports blinking.
                            attribute = LineDisplayTextAttribute.Blink;
                        }
                    }

                    if (await lineDisplay.DefaultWindow.TryClearTextAsync() &&
                        await lineDisplay.DefaultWindow.TryDisplayTextAsync(text, attribute, position))
                    {
                        rootPage.NotifyUser("Text displayed successfully", NotifyType.StatusMessage);
                    }
                    else
                    {
                        // We probably lost our claim.
                        rootPage.NotifyUser("Unable to display text", NotifyType.ErrorMessage);
                    }
                }
                else
                {
                    rootPage.NotifyUser("Unable to claim the Line Display", NotifyType.ErrorMessage);
                }
            }
        }