wpf customControl binding itemscontrol DataTemplate button

后端 未结 2 1597
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-20 05:49

i am new to WPF so i am stuck with some binding on my customcontrol click button.

I have textbox that has watermark and selctedItems properties. Control if selectedi

2条回答
  •  忘掉有多难
    2020-12-20 06:40

    Finally i manage to make it work, with help and guidance from Jaun it still didnt work (i tried probably 10 different things and it was in DataContext .. it was never binded.

    So on my override OnApplyTemplate i added this.DataContext = this ... so i missed that part.

    I used AttachedCommandBehavior (nuget) for command

    code:

    public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.DataContext = this;
    
            ItemsControl itmControl = GetTemplateChild("PART_SelectedItemsHost") as ItemsControl;
    
            if (itmControl != null)
            {
                itmControl.MouseLeftButtonDown += new MouseButtonEventHandler(itmControl_MouseLeftButtonDown);
    
                // blind click on X buttons in ItemsControl
            }
    
        }
    

提交回复
热议问题