Inheritance, DependencyProperty and Custom Control...

Joined
Jan 10, 2007
Messages
43,898
Location
In The Machine
Hi !

I have a problem with two custom controls that I want to make :
  • *the first one is a Page derived controls, which contains a TabControl.
  • the second one is a HeaderedContentControl, made to be contained by the first one.
The purpose is to navigate to a page and directly display a tab.

So, the navigation to a tab is not a problem. The problem is to have different pages with different tabs... :(

I have made this classes (I just copy relevant code) :

[ContentProperty("MyTabs")]
public class MyPage : Page
{
*** public List MyTabs
*** {
******* get { return (List)GetValue(MyTabsProperty); }
******* set { SetValue(MyTabsProperty, value); }
*** }
*** public static readonly DependencyProperty MyTabsProperty =
******* DependencyProperty.Register("MyTabs", typeof(List), typeof(FrameworkElement), new FrameworkPropertyMetadata(new List()));

*** static MyPage()
*** {
******* DefaultStyleKeyProperty.OverrideMetadata(typeof(MyPage), new FrameworkPropertyMetadata(typeof(MyPage)));
*** }

*** public MyPage() : base() { }

*** public override void OnApplyTemplate()
*** {
******* base.OnApplyTemplate();
******* TabControl tabControl = GetTemplateChild("PART_TabControl") as TabControl;
******* if (tabControl != null)
******* {
*********** Binding tabsBinding = new Binding();
*********** tabsBinding.Source = this.MyTabs;
*********** tabControl.SetBinding(TabControl.ItemsSourceProperty, tabsBinding);
******* }
*** }
}


public class MyTab : HeaderedContentControl
{
*** static MyTab()
*** {
******* //DefaultStyleKeyProperty.OverrideMetadata(typeof(MyTab), new FrameworkPropertyMetadata(typeof(MyTab)));
*** }
*** public void Reset()
*** {
******* //...
*** }
*** public void Compute()
*** {
******* //...
*** }
}



And, when I use this classes like this :


***
*******
*******
***



*******
*******
*******
*******



*******
*******
*******



... my two frames contain the all seven tabs.

Actually, when I add a tab in MyPage1 or MyPage2, the tab is added in the MyTabs property in MyPage...

I don't know how to tell WPF that the MyTabs property is different for each derived class.

Somebody have an answer ?




More...

View All Our Microsoft Related Feeds
 
Back
Top