Exemple #1
0
        public override void InitElements()
        {
            _icon.IsHover = false;
            _icon.SetSizePolicy(SizePolicy.Fixed, SizePolicy.Fixed);
            _icon.SetSize(40, 30);
            _icon.KeepAspectRatio(true);
            _icon.SetAlignment(ItemAlignment.Left, ItemAlignment.VCenter);
            if (_isChecked)
            {
                _icon.SetImage(Factory.Resources.SwitcherOn);
            }
            else
            {
                _icon.SetImage(Factory.Resources.SwitcherOff);
            }

            _text.IsHover = false;
            _text.SetTextAlignment(ItemAlignment.Left, ItemAlignment.VCenter);
            _text.SetMargin(_icon.GetWidth() + _spacing);
            SetMaxWidth(_text.GetTextWidth() + _icon.GetWidth() + _spacing);

            AddItems(
                _icon,
                _text
                );

            EventMouseHover += (sender, args) =>
            {
                _isHovered = true;
                UpdateImage();
            };
            EventMouseLeave += (sender, args) =>
            {
                _isHovered = false;
                UpdateImage();
            };
            EventMouseClick += (sender, args) =>
            {
                Toggle();
            };
        }