1. Welcome Guest! In order to create a new topic or reply to an existing one, you must register first. It is easy and free. Click here to sign up now!.
    Dismiss Notice

Inheritance, DependencyProperty and Custom Control...

Discussion in 'Microsoft News' started by NewsBot, Apr 2, 2008.

  1. NewsBot

    NewsBot I Got News

    Joined:
    Feb 8, 2006
    Messages:
    1,813
    Operating System:
    Windows Vista Home Premium
    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... [​IMG]

    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 ?






     

Share This Page