Click Button from Generic.xaml?

前端 未结 2 1492
太阳男子
太阳男子 2021-01-14 09:35

I am writing a custom control in Silverlight and I am having issues getting my Button to click to the Generic.xaml file. This does not work:

    

        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-14 10:27

    You have to override the OnApplyTemplate() on your custom control class (C# File).

    Like this.

        public override void OnApplyTemplate()
        {
            Button btn = GetTemplateChild("ScrollLeft") as Button;
            Debug.Assert(btn != null);
        }
    

    Also, you have to make one more change in the control template in Generic.Xaml like below.

    
            
                
                    
                        
                    
                
            
    

    Note: I removed the Click event handler.

提交回复
热议问题