示例#1
0
        private async void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                StackPanel stackPanel = new StackPanel();

                TextBlock NameOfStyle = new TextBlock
                {
                    Text   = "Название стиля",
                    Margin = new Thickness(10)
                };

                TextBox NameOfStyleTextBlock = new TextBox
                {
                    MaxLength = 255
                };

                RelativePanel relativePanel = new RelativePanel
                {
                    FlowDirection       = FlowDirection.LeftToRight,
                    HorizontalAlignment = HorizontalAlignment.Stretch
                };
                relativePanel.Children.Add(NameOfStyle);
                relativePanel.Children.Add(NameOfStyleTextBlock);
                RelativePanel.SetAlignLeftWithPanel(NameOfStyle, true);
                RelativePanel.SetAlignRightWithPanel(NameOfStyleTextBlock, true);
                RelativePanel.SetRightOf(NameOfStyleTextBlock, NameOfStyle);
                stackPanel.Children.Add(relativePanel);

                ContentDialog deleteFileDialog = new ContentDialog()
                {
                    Title               = "Подтверждение действия",
                    Content             = stackPanel,
                    PrimaryButtonText   = "ОК",
                    MaxWidth            = 500,
                    SecondaryButtonText = "Отмена"
                };

                ContentDialogResult result = await deleteFileDialog.ShowAsync();

                if (result == ContentDialogResult.Primary)
                {
                    await _styleService.CreateStyle(NameOfStyleTextBlock.Text);

                    (DataContext as ApplicationViewModel).Styles = await _styleService.GetAllStyles();
                }
                else if (result == ContentDialogResult.Secondary)
                {
                    //header.Text = "Отмена действия";
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Message: {ex.Message}\r\nSource: { ex.Source}\r\nTarget Site Name: { ex.TargetSite.Name}\r\n{ ex.StackTrace}");
            }
        }