English 中文(简体)
I m试图利用CotentDialog在UWP XAML的数据库中获取一些数据并改变数据,但我遇到了一些问题。
原标题:I m trying to use CotentDialog to get some data and change it in my database in UWP XAML but I encountered some issues
private async void iconu_PointerPressed(object sender, PointerRoutedEventArgs eventArgs)
{
    if (BigGrid.SelectedIndex == -1)
    {
        ContentDialog dialog2 = new ContentDialog
        {
            Title = "Please select a Grid!",
            Content = "When selected it will have a border :)",
            CloseButtonText = "Cancel",
        };
        ContentDialogResult result2 = await dialog2.ShowAsync();
        return;
    }
    ContentDialog dialog = new ContentDialog
    {   

        Title = "Please enter your information",
        CloseButtonText = "Cancel",
        PrimaryButtonText = "OK",
        Content = new StackPanel
        {
            Children =
        {
            new TextBlock { Text = "Title:" },
            new TextBox { Name = "TitleTextBox" },
            new TextBlock { Text = "Description:" },
            new TextBox { Name = "DescriptionTextBox" },
            new TextBlock { Text = "Select Date:" },
            new DatePicker { Name = "DatePicker" },
            new TextBlock { Text = "Select Time:" },
            new TimePicker { Name = "TimePicker" }
        }
        }
    };

    ContentDialogResult result = await dialog.ShowAsync();
    if (result == ContentDialogResult.Primary)
        {
            TextBox titleTextBox = dialog.FindName("TitleTextBox") as TextBox;
            TextBox descriptionTextBox = dialog.FindName("DescriptionTextBox") as TextBox;
            DatePicker datePicker = dialog.FindName("DatePicker") as DatePicker;
            TimePicker timePicker = dialog.FindName("TimePicker") as TimePicker;

            if (titleTextBox != null && descriptionTextBox != null && datePicker != null && timePicker != null)
            {
                Debug.WriteLine("All controls are not null.");
                string title = titleTextBox.Text;
                string description = descriptionTextBox.Text;
                DateTime selectedDateTime = datePicker.Date.DateTime.Date + timePicker.Time;
                Debug.WriteLine($"1.TitleTextBox: {titleTextBox.Text}, DescriptionTextBox: {descriptionTextBox.Text}, DatePicker: {datePicker.Date}, TimePicker: {timePicker.Time}");

            int Id = ((Note)BigGrid.SelectedItem).Id;
                Notedatabase.UpdateData(Id, title, description, selectedDateTime);
                BigGrid.ItemsSource = Notedatabase.GetData();
            }
            else
            {
                Debug.WriteLine("Some controls are null.");
                Debug.WriteLine($"2.TitleTextBox: {titleTextBox}, DescriptionTextBox: {descriptionTextBox}, DatePicker: {datePicker}, TimePicker: {timePicker}");
                ContentDialog dialog1 = new ContentDialog
                {
                    Title = "Please input All values!",
                    Content = "Thank you :)", 
                    CloseButtonText = "Cancel",
                };
                await dialog1.ShowAsync();
            }
    }

我正在从当地保存的数据库中获取数据,BigGrid是GredView。 项目Template

我预计会得到这些数值,但会把其他方言箱“让所有价值都投入” throw。

Debug.WriteLine($"2.TitleTextBox: {titleTextBox}, DescriptionTextBox: {descriptionTextBox}, DatePicker: {datePicker}, TimePicker: {timePicker}");

这条线表明,内部没有任何东西。

我认为这是错误的吗? 但我不敢肯定

TextBox titleTextBox = dialog.FindName("TitleTextBox") as TextBox;
            TextBox descriptionTextBox = dialog.FindName("DescriptionTextBox") as TextBox;
            DatePicker datePicker = dialog.FindName("DatePicker") as DatePicker;
            TimePicker timePicker = dialog.FindName("TimePicker") as TimePicker;

任何帮助都将受到高度赞赏:D

问题回答
            StackPanel stackPanel = (StackPanel)dialog.Content;
            string title = ((TextBox)stackPanel.Children[1]).Text;
            string description = ((TextBox)stackPanel.Children[3]).Text;
            DateTime selectedDate = ((DatePicker)stackPanel.Children[5]).Date.DateTime;
            TimeSpan selectedTime = ((TimePicker)stackPanel.Children[7]).SelectedTime.Value;

我使用了这一说法,并做了以下工作:





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签