2010-04-20 5 views
0

SL4 애플리케이션에서 TabItem을 리 스타일해야합니다 (실제로는 헤더에 버튼을 추가하십시오).Silverlight TabItem 템플릿이 올바르게 작동하지 않습니다.

그래서 Tabbox의 컨트롤 템플릿을 here에서 가져 와서 내가 원하는 기능을 추가했습니다.

이것은 게시 된 제어 템플릿이 어떻게 든 "임의"로 작동한다고 생각합니다. 선택한 TabItem 헤더 위로 마우스를 가져 가면 매번이 선택됩니다 (이 경우 동적으로 tabitems를 추가 할 수 있습니다). 아무튼 클릭하면 !! (이 동작은 기본 동작이 아닙니다. 즉, 사용자가이 탭 항목을 선택하려면 머리글을 클릭해야합니다.)

나는 행운과 함께 왜 이런 행동을하는지 찾으려고 노력했습니다! 내 어둠을 밝힐 수있는 사람이 있습니까 ???

미리 감사드립니다.

답변

0

오류가 제어 템플릿에 없지만 클래스에서 스타일이 적용된 것으로 나타났습니다.

상세

는 :

공용 클래스 WorkspaceViewModel : 스타일이 적용 된 클래스는 (그 안에 당신이 "잘못된 행동"에 대한 내 의견을 볼 수 있습니다) 다음은 {

public WorkspaceViewModel() 
    { 
     DefaultStyleKey = typeof(WorkspaceViewModel); 
    } 
    public override void OnApplyTemplate() 
    { 
     base.OnApplyTemplate(); 
     Button closeButtonSel = base.GetTemplateChild("PART_CloseTopSelected") as Button; 
     Button closeButtonUnsel = base.GetTemplateChild("PART_CloseTopUnSelected") as Button; 
     if (closeButtonSel != null) 
      closeButtonSel.Click += new RoutedEventHandler(closeButtonSel_Click); 
     if (closeButtonUnsel != null) 
      closeButtonUnsel.Click += new RoutedEventHandler(closeButtonSel_Click); 

     //this part is causing the effect i was complaining about! 
     //and has to be removed 
     this.MouseEnter += delegate(object sender, MouseEventArgs e) 
     { 
      IsSelected = true; 
     }; 


    } 

    void closeButtonSel_Click(object sender, RoutedEventArgs e) 
    { 
     //this is the close request method used in the CloseTabItemCommand 
     OnRequestClose(); 

    } 


    #region CloseTabItemCommand 

    private RelayCommand closeTabItemCommand; 
    public ICommand CloseTabItemCommand 
    { 
     get 
     { 
      if (this.closeTabItemCommand == null) 
       this.closeTabItemCommand = new RelayCommand(p => this.OnRequestClose(), p => this.CanCloseTabItem()); 

      return this.closeTabItemCommand; 
     } 
    } 
    private bool CanCloseTabItem() 
    { 
     return true; 
    } 

    public event EventHandler RequestClose; 
    private void OnRequestClose() 
    { 
     if (RequestClose != null) 
      RequestClose(this, EventArgs.Empty); 
    } 
    #endregion 
} 
TabItem의
관련 문제