This is a migrated thread and some comments may be shown as answers.

Custom RadTool Bar Implementation

1 Answer 79 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Kiran
Top achievements
Rank 1
Kiran asked on 31 Aug 2010, 08:27 AM
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
                    
}

1 Answer, 1 is accepted

Sort by
0
Viktor Tsvetkov
Telerik team
answered on 01 Sep 2010, 11:53 AM
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
Tags
ToolBar
Asked by
Kiran
Top achievements
Rank 1
Answers by
Viktor Tsvetkov
Telerik team
Share this question
or