or
I have created dynamic validation on scheme editing. But I encountered with few problems.
1) How to get active connection correctly? I use method described below:
01.
private
RadDiagramConnection GetActiveConnection()
02.
{
03.
var toolService = ServiceLocator.GetService<IToolService>();
04.
if
(toolService ==
null
|| toolService.ActiveTool ==
null
)
return
null
;
05.
06.
var toolType = toolService.ActiveTool.GetType();
07.
var fieldInfo = toolType.GetField(
"activeConnection"
, BindingFlags.Instance | BindingFlags.NonPublic);
08.
if
(fieldInfo ==
null
)
return
null
;
09.
return
fieldInfo.GetValue(toolService.ActiveTool)
as
RadDiagramConnection;
10.
}
<
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
>
<
telerik:RadPane
Name
=
"radPaneTOC"
IsPinned
=
"True"
CanUserClose
=
"False"
CanDockInDocumentHost
=
"False"
CanUserPin
=
"False"
TitleTemplate
=
"{StaticResource PaneHelpHeaderTemplate}"
>
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"
);
}
}
}
}