Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > ToolBar > Custom RadTool Bar Implementation

Not answered Custom RadTool Bar Implementation

Feed from this thread
  • Kiran avatar

    Posted on Aug 31, 2010 (permalink)

    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
                        
    }

    Reply

  • Viktor Tsvetkov Viktor Tsvetkov admin's avatar

    Posted on Sep 1, 2010 (permalink)

    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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > ToolBar > Custom RadTool Bar Implementation
Related resources for "Custom RadTool Bar Implementation"

WPF ToolBar Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]