Custom RadTool Bar Implementation

2 posts, 0 answers
  1. Kiran
    Kiran avatar
    36 posts
    Member since:
    Jul 2010

    Posted 31 Aug 2010 Link to this post

    Hi

    I am trying to implement a custom RadToolBar control using control templating mechanism. I am having trouble with exposing Items property and not able to figure out how to expose it.

    Code in Generic.Xaml

    <Style TargetType="{x:Type local:TngToolBar}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:TngToolBar}">
                        <ControlsNavigation:RadToolBar Name="PART_BaseControl"
                            DataContext="{TemplateBinding Property=DataContext}"                           
                            ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type local:TngToolBar}},Mode=TwoWay, Path=ItemsSource}"
                              
                            ToolTip="{TemplateBinding Property=ToolTip}"
                            >
                        </ControlsNavigation:RadToolBar>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    Base Class Code:

    public class TngBaseTemplateControl : Control
    {
        /*
         * Need to get the type of the control template using reflection, on "OnApplyTemplate"
         */
        protected TngBaseTemplateControl()
        {
        }
    }


    Custom Toolbar Class:

    public class TngToolBar : TngBaseTemplateControl 
    {
        private Object _itemsSource;
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            RadToolBar menu = this.Template.FindName("PART_BaseControl", this) as RadToolBar;
        }
        static TngToolBar()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TngToolBar), new FrameworkPropertyMetadata(typeof(TngToolBar)));
        }
        #region Property: DataContext
        private Object _dataContext;
        public Object DataContext
        {
            get { return GetValue(DataContextProperty); }
            set { SetValue(DataContextProperty, value); }
        }
        public static readonly DependencyProperty DataContextProperty =
            DependencyProperty.Register(
                "DataContext", typeof(Object), typeof(TngToolBar),
                 new FrameworkPropertyMetadata
                 {
                     PropertyChangedCallback = (obj, e) =>
                     {
                         (obj as TngToolBar).UpdateDataContext((Object)e.NewValue);
                     }
                 });
        private void UpdateDataContext(Object sel)
        {
            _dataContext = sel;
        }
        #endregion
        #region Property: ItemsSource
        public Object ItemsSource
        {
            get { return GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }
        public static readonly DependencyProperty ItemsSourceProperty =
            DependencyProperty.Register(
                "ItemsSource", typeof(Object), typeof(TngToolBar),
                new FrameworkPropertyMetadata
                {
                    PropertyChangedCallback = (obj, e) =>
                    {
                        (obj as TngToolBar).UpdateItemsSource(e.NewValue);
                    }
                });
        private void UpdateItemsSource(Object sel)
        {
            _itemsSource = sel;
        }
        #endregion
                        
    }

  2. Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 01 Sep 2010 Link to this post

    Hi Kiran,

    I am not sure what your problem is, but why do not you just add Items dependency property and bind it in your ControlTemplate? If this is not your problem, could you please be more descriptive?

    All the best,
    Viktor Tsvetkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top