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
Base Class Code:
Custom Toolbar Class:
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
}