예제 #1
0
    public void ZHistory()
    {
        var p = new KPopupListBox {
            PlacementTarget = this, Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint
        };

        p.Control.ItemsSource = _history;
        p.OK += o => print.it((o as PrintServerMessage).Text);
        Dispatcher.InvokeAsync(() => p.IsOpen = true);
    }
예제 #2
0
    object _items;     //List<string> or Func<List<string>>

    ///
    public KCheckTextBox(KCheckBox c, KTextBox t, Button button = null)
    {
        this.c  = c;
        this.t  = t;
        c.Tag   = this;
        t.Tag   = this;
        t.Small = true;
        _button = button;
        if (_button != null)
        {
            //_button.ClickMode = ClickMode.Press; //open on button down. But then Popup.StaysOpen=false does not work. Tried async, but same. //SHOULDDO: replace Popup in KPopupListBox with KPopup.
            _button.Click += (_, _) => {
                if (_popup?.IsOpen ?? false)
                {
                    _popup.IsOpen = false;
                    return;
                }
                List <string> a = null;
                switch (_items)
                {
                case List <string> u: a = u; break;

                case Func <List <string> > u: a = u(); break;
                }
                if (a.NE_())
                {
                    return;
                }
                if (_popup == null)
                {
                    _popup = new KPopupListBox {
                        PlacementTarget = t
                    };
                    _popup.OK += o => {
                        c.IsChecked = true;
                        var s = o as string;
                        t.Text = s;
                        t.Focus();
                    };
                }
                _popup.Control.ItemsSource = null;
                _popup.Control.ItemsSource = a;
                _popup.Control.MinWidth    = t.ActualWidth + _button.ActualWidth - 1;
                _popup.IsOpen = true;
            };
        }
    }