[英]How to open content dialog without button click fron c# code to xaml code for UWp app
[英]c# - XAML: how to open an menu with textbox and button by button click?
我想在按下應用欄中的按鈕時使用文本框和按鈕打開一個矩形框菜單。 讓我再次解釋我的問題。
我想在我的應用程序中有搜索選項。 因此,我的應用程序欄中有搜索圖標。 當用戶要搜索時,他向上滑動應用欄,然后按搜索圖標。
按下搜索圖標時,應打開一個帶有矩形框的菜單,其中包含文本框和按鈕。
我不知道如何在C#和XAML中對此進行編碼。 請幫我。 每個答案將不勝感激。
您可以使用WP工具包中的 CustomMessageBox
並在其中插入Textbox
TextBox txtBox = new TextBox();
txtBox.Width = 460;
txtBox.Text = selectedChild.Name;
txtBox.HorizontalAlignment = HorizontalAlignment.Center;
txtBox.MaxLength = 14;
CustomMessageBox messageBox = new CustomMessageBox();
messageBox.Caption = "hello";
messageBox.Content = txtBox;
messageBox.LeftButtonContent = "OK";
messageBox.RightButtonContent = "Cancel";
messageBox.IsFullScreen = false;
messageBox.Dismissed += MessageBoxDismissed;
messageBox.Show();
這是回調
private void MessageBoxDismissed(object sender, DismissedEventArgs e)
{
CustomMessageBox messageBox = sender as CustomMessageBox;
if (messageBox != null && e.Result == CustomMessageBoxResult.LeftButton)
{
TextBox tb = messageBox.Content as TextBox;
if (tb != null && !string.IsNullOrEmpty(tb.Text.Trim()))
{
//do your stuff
}
}
else
{
}
}
這個問題的完美答案是使用NuGet。 您可以從這里下載
然后,您可以通過單擊以下鏈接來在CustomMessageBox中初始化文本框的代碼: 在customMessageBox中顯示兩個文本框?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.