当用户单击DataGrid中的一行时,我触发了一个Content Dialog.内容对话框的主要目标是允许用户通过内容对话框中名为‘Cmnt_Apprvl_Mgmt’的TextBox控件输入和保存注释.这种逻辑现在起作用了.
现在,我希望从DataGrid中单击的行中的一些数据出现在Content Dialog中.我一直想不出怎么做这件事.
我将‘rowModel’(来自数据网格的数据)作为参数传递给新的内容对话框(V3). 我希望之前为特定行输入的任何备注都填充到内容对话框中的文本框‘Cmnt_Apprvl_Mgmt’中.
提前感谢StackOverflow-贡献者,你们在这个项目中对我帮助很大.这是非常感谢的.
我的代码:(XAML)
<ContentDialog x:Name="MgmtApprovalDialog"
Title = "Enter Management Approval Comment"
PrimaryButtonText="Save"
CloseButtonText="Cancel"
Opened="MgmtApprovalDialog_Opened"
PrimaryButtonClick="MgmtApprovalDialog_PrimaryButtonClick">
<StackPanel>
<TextBox x:Name="Cmnt_Apprvl_Mgmt" PlaceholderText="Enter Comment" Margin="0 0 0 0" TextWrapping="Wrap" Height="80" TextChanged="Cmnt_Apprvl_Mgmt_TextChanged"/>
<TextBlock x:Name="errorTextBlock" Margin="0 10 0 5" FontWeight="Bold" FontStyle="Oblique"/>
<!-- Content body -->
<TextBlock Name="body" TextWrapping="Wrap">
<TextBlock.Text>
When a target is not met, a comment from management is required (long and detailed)
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ContentDialog>
C#
private void MgmtApprovalDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
// Ensure the comment field is empty. If a required field
// is empty, set args.Cancel = true to keep the dialog open.
if (string.IsNullOrEmpty(Cmnt_Apprvl_Mgmt.Text))
{
args.Cancel = true;
errorTextBlock.Text = "Comment is required.";
}
}
private void DataGrid_Detail_PointerReleased(object sender, PointerRoutedEventArgs e)
{
DataGridRow clickedRow = FindParent<DataGridRow>((UIElement)e.OriginalSource);
if (clickedRow != null)
{
Approvals rowModel = (Approvals)clickedRow.DataContext;
// Do stuff
// DisplayCommentDialog();
//DisplayCommentDialog_v2(rowModel);
DisplayCommentDialog_v3(rowModel);
}
}
// +---------------------------------------------------------
// | DISPLAY COMMENT DIALOG V3
// +---------------------------------------------------------
private async void DisplayCommentDialog_v3(Approvals rowModel)
{
ContentDialogResult result = await MgmtApprovalDialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
// Save button clicked
Debug.WriteLine($"+-------------------------------------------------------------------");
Debug.WriteLine($"| Hello - inside DisplayCommentDialog_v3 Primary Button Clicked!");
Debug.WriteLine($"| Hello - Comment ID : {rowModel.Comment_ID}");
Debug.WriteLine($"| Hello - Comment Text: {Cmnt_Apprvl_Mgmt.Text}");
Debug.WriteLine($"+-------------------------------------------------------------------");
SaveMgMtApprovalComment(rowModel.Comment_ID, Cmnt_Apprvl_Mgmt.Text);
// Before refreshing the DataGrid_Detail you must re-pull from the server (this may be a design flaw.)
GetSQLData_Approvals();
// Refresh DataGrid_Detail so the user can see what was just entered
PopulateApprovalDetDG(v_product);
}
else
{
// User pressed Cancel, ESC, or the back arrow.
// Terms of use were not accepted.
Debug.WriteLine($"+-------------------------------------------------------------------");
Debug.WriteLine($"| Hello - inside DisplayCommentDialog_v3 (Cancel, ESC, or back arrow)");
Debug.WriteLine($"+-------------------------------------------------------------------");
}
}