Hi,
I'm trying to add a button to the TitleTemplate of RadPanes (beside the Pin), handle the click event on this button and display a message specific to the targeted RadPanel.
So far, I've applied the solution presented here: http://blogs.telerik.com/xamlteam/posts/09-08-19/customizing-the-header-of-radpane-control-and-adding-behavior-to-it.aspx
My DataTemplate (in Resources):
Applied to:
And my custom property definition (which is basically a Copy-Paste of the reference above) :
As mentioned in the comment, I can't access to the parent (always null), which would allow me to get its Help content (custom property) (or do anything else with it).
I'm not sure if that is the good approach, I heard and read a little about custom Commands (here), but I'm not very familiar with the process.
As a side note, I would like to define the visibility and the content (text) of this button programmatically.
Thank you,
JL.
I'm trying to add a button to the TitleTemplate of RadPanes (beside the Pin), handle the click event on this button and display a message specific to the targeted RadPanel.
So far, I've applied the solution presented here: http://blogs.telerik.com/xamlteam/posts/09-08-19/customizing-the-header-of-radpane-control-and-adding-behavior-to-it.aspx
My DataTemplate (in Resources):
<
Window.Resources
>
<
DataTemplate
x:Key
=
"PaneHelpHeaderTemplate"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
ContentPresenter
Content
=
"{Binding}"
Margin
=
"0,0,0,0"
/>
<
telerik:RadButton
Content
=
"Help"
view:HelpButton.IsHelp
=
"True"
/>
</
StackPanel
>
</
DataTemplate
>
</
Window.Resources
>
Applied to:
<
telerik:RadPane
Name
=
"radPaneTOC"
IsPinned
=
"True"
CanUserClose
=
"False"
CanDockInDocumentHost
=
"False"
CanUserPin
=
"False"
TitleTemplate
=
"{StaticResource PaneHelpHeaderTemplate}"
>
And my custom property definition (which is basically a Copy-Paste of the reference above) :
public
static
class
HelpButton
{
public
static
readonly
DependencyProperty IsHelp = DependencyProperty.RegisterAttached(
"IsHelp"
,
typeof
(
bool
),
typeof
(Telerik.Windows.Controls.RadButton),
new
PropertyMetadata(OnIsHelpButtonChanged));
public
static
bool
GetIsHelp(DependencyObject obj)
{
return
(
bool
)obj.GetValue(IsHelp);
}
public
static
void
SetIsHelp(DependencyObject obj,
bool
value)
{
obj.SetValue(IsHelp, value);
}
private
static
void
OnIsHelpButtonChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
bool
oldValue = (
bool
)e.OldValue;
bool
newValue = (
bool
)e.NewValue;
var button = d
as
ButtonBase;
if
(button !=
null
&& oldValue != newValue)
{
if
(!oldValue && newValue)
{
button.Click += OnCloseButtonClick;
}
else
{
button.Click -= OnCloseButtonClick;
}
}
}
private
static
void
OnCloseButtonClick(
object
sender, RoutedEventArgs args)
{
var button = sender
as
FrameworkElement;
if
(button !=
null
)
{
// NONE OF THEM WORK
var pane = button.ParentOfType<RadPane>();
// var pane = button.GetVisualParent<RadPane>();
// var pane = ((System.Windows.Controls.StackPanel)button.Parent).Parent;
if
(pane !=
null
)
{
Console.WriteLine(
"Parent found"
);
}
}
}
}
As mentioned in the comment, I can't access to the parent (always null), which would allow me to get its Help content (custom property) (or do anything else with it).
I'm not sure if that is the good approach, I heard and read a little about custom Commands (here), but I'm not very familiar with the process.
As a side note, I would like to define the visibility and the content (text) of this button programmatically.
Thank you,
JL.