将弹出按钮设置为按钮

时间:2016-06-27 14:30:56

标签: c# xaml uwp

我只想学点东西; 特别 - 尝试创建一个弹出按钮,将其设置为一个按钮,最后显示该弹出按钮。

这是我的代码:

private void Button_Click(object sender, RoutedEventArgs e)
{
    if (FirstNameBox.Text == "" || SecondNameBox.Text == "" || AvatarButton.SelectedItem == null)
    {
        var button = sender as Button;
        Flyout flyout = new Flyout();
        var txtblock = new TextBlock();
        txtblock.HorizontalAlignment = HorizontalAlignment.Center;
        txtblock.Text = "You haven't set something.";

        flyout.Placement = FlyoutPlacementMode.Top;
        flyout.Content = txtblock;

        FlyoutBase.SetAttachedFlyout(button, flyout);

        button.Flyout.ShowAt(button);
    }

投掷的错误是我的按钮叫"按钮"没有任何弹出窗口,但我只是附加它"显示" :C

有谁知道发生了什么?

1 个答案:

答案 0 :(得分:0)

您的错误就在这一行:

button.Flyout.ShowAt(button);

试着写下这个:

flyout.ShowAt(button);