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();
}
}
I am getting data from a Locally saved Database, BigGrid is a GridView.ItemTemplate
I expected to get the values to save but it kept throwing the other dialog box "Please input All values"
Debug.WriteLine($"2.TitleTextBox: {titleTextBox}, DescriptionTextBox: {descriptionTextBox}, DatePicker: {datePicker}, TimePicker: {timePicker}");
This line shows that there is nothing inside
I think I did this wrongly? But I'm not too sure
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;
Any help would be greatly appreciated :D
I used this instead and it worked :)