简体   繁体   English

CodeGo.net> XAML:如何通过单击文本框和按钮打开菜单?

[英]c# - XAML: how to open an menu with textbox and button by button click?

I want to open an rectangular box menu with textbox and button, when the button in appbar pressed. 我想在按下应用栏中的按钮时使用文本框和按钮打开一个矩形框菜单。 Let me explain my question again. 让我再次解释我的问题。

I want to have search option in my app. 我想在我的应用程序中有搜索选项。 so, i have search icon in my app bar. 因此,我的应用程序栏中有搜索图标。 when user wants to search he swipes up the app bar and press search icon. 当用户要搜索时,他向上滑动应用栏,然后按搜索图标。

When the search icon is pressed, a menu with rectangular box contains textbox & button, should be opened. 按下搜索图标时,应打开一个带有矩形框的菜单,其中包含文本框和按钮。

I dunno how to code for this in C# and XAML. 我不知道如何在C#和XAML中对此进行编码。 please help me. 请帮我。 Every answer will be appreciated. 每个答案将不胜感激。

You can use CustomMessageBox from WP toolkit and insert a Textbox in it 您可以使用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();

here is the callback 这是回调

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
    {
    }
}

The Perfect answer for this question is use to NuGet. 这个问题的完美答案是使用NuGet。 you can download it from here 您可以从这里下载

And you can the code to initialize the textbox in CustomMessageBox by clicking the following link: display two textbox in customMessageBox? 然后,您可以通过单击以下链接来在CustomMessageBox中初始化文本框的代码: 在customMessageBox中显示两个文本框?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM