如何以编程方式在按钮中添加弹出文本

时间:2018-06-11 11:33:09

标签: c#-3.0 uwp-xaml

我正在生成此按钮,我想在弹出窗口中设置文本

            var button = new Button();            
            button.Height = height;
            button.Width = width;

            button.Margin = new Thickness(left, top, 0, 0);
            button.BorderBrush = new SolidColorBrush(Windows.UI.Colors.Red);
            button.BorderThickness = new Thickness(2);
            button.Background = new SolidColorBrush(Windows.UI.Colors.Transparent);
            button.Flyout = new Flyout();

如何设置button.Flyout的内容?

1 个答案:

答案 0 :(得分:0)

  

如何设置button.Flyout的内容?

您可以将按钮实例传递给follow方法。

public void AddFlyoutToBtn(Button TargetBtn)
{
    TargetBtn.Flyout = new Flyout()
    {
        Content = new StackPanel
        {
            Children =
            {
                new TextBlock
                {
                    Text = "All items will be removed. Do you want to continue?",
                    Margin = new Thickness(10, 10, 0, 0)
                 },
                new Button
                {
                    Content = "Yes, empty my cart"
                }
            }
        }
    };
}