如何使用mdAutocomplete openPanel方法

时间:2017-09-26 12:35:09

标签: angular angular-material angular-material2

我正在尝试创建一个清除mdAutocomplete控件并打开面板的按钮。

这样的事情:

clearValue() {
  this.stateCtrl.setValue("");
  this.trigger.openPanel();
}

这里是完整代码的插件: https://plnkr.co/edit/KC8f1bHaDpWXEkLxzLta?p=preview

如果我在clearValue函数中设置了一个断点,并在控制台中调用this.trigger.openPanel()面板打开,但是当我让代码运行时,面板永远不会打开。

1 个答案:

答案 0 :(得分:2)

解决问题的最简单方法是阻止传播到关闭弹出窗口的处理程序:

public class MyButton : Button 
{

private static string Image_path = "ms-appx:///assets/Button.png";

        public MyButton()
        {

            ImageBrush brush = new ImageBrush()
            {
                ImageSource = new BitmapImage(new Uri(MyButton.Image_path))
            };
            this.Background = brush;

            this.PointerEntered += a;

        }

        // This almost work, but the image is flickering when event is fired
        private void a(object sender, PointerRoutedEventArgs e)
        {
            ImageBrush brush = new ImageBrush()
            {
                ImageSource = new BitmapImage(new Uri(MyButton.Image_path))
            };
            //this.Foreground = brush;
            this.Background = brush;
        }
}

<强> Forked Plunker