We are extensively using RadContexMenu in our Silverlight app. Context menus are connected to controls in XAML. During memory profiling we've find out that RadContextMenu instances are not collected by GC. Do you have any hint how to dispose these instances?
Regards,
Wojtek
Regards,
Wojtek
4 Answers, 1 is accepted
0
Hello Wojtek,
May I ask you to share more details about your scenario. Where do you define RadContextMenu - is it in the MainPage (or any other UserControl)? Could you share the parts of the XAML where you are using RadContextMenu?
I'm looking forward to hearing from you.
Regards,
Rosen Vladimirov
Telerik
May I ask you to share more details about your scenario. Where do you define RadContextMenu - is it in the MainPage (or any other UserControl)? Could you share the parts of the XAML where you are using RadContextMenu?
I'm looking forward to hearing from you.
Regards,
Rosen Vladimirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Wojtek
Top achievements
Rank 1
answered on 09 Jul 2013, 01:05 PM
Rosen,
RadContextMenu is defined in dynamicaly created UserControl. Below is the example of XAML. We use StandardOpenContextMenu which derives from RadContextMenu.
RadContextMenu is defined in dynamicaly created UserControl. Below is the example of XAML. We use StandardOpenContextMenu which derives from RadContextMenu.
<
UserControl
xmlns:Controls
=
"clr-namespace:ProIntegra.UDC.Frontend.GUI.Controls"
x:Class
=
"ProIntegra.UDC.Frontend.GUI.Controls.NavigatorControl"
mc:Ignorable
=
"d"
d:DesignWidth
=
"850"
Height
=
"26"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"#FFF7F7F7"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"auto"
/>
<
ColumnDefinition
Width
=
"auto"
/>
<
ColumnDefinition
Width
=
"auto"
/>
<
ColumnDefinition
Width
=
"auto"
/>
<
ColumnDefinition
Width
=
"auto"
/>
<
ColumnDefinition
Width
=
"300"
/>
<
ColumnDefinition
Width
=
"100"
/>
<
ColumnDefinition
Width
=
"100"
/>
<
ColumnDefinition
Width
=
"100"
/>
<
ColumnDefinition
Width
=
"100"
/>
<
ColumnDefinition
Width
=
"100"
/>
<
ColumnDefinition
Width
=
"*"
/>
</
Grid.ColumnDefinitions
>
<
Controls:ImageButton
x:Name
=
"buttonBackward"
Grid.Column
=
"0"
Image
=
"/Controls;component/Navigator/Images/navigationBackward.png"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Height
=
"26"
Width
=
"26"
IsEnabled
=
"False"
/>
<
Controls:ImageButton
x:Name
=
"buttonForward"
Grid.Column
=
"1"
Image
=
"/Controls;component/Navigator/Images/navigationForward.png"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Height
=
"26"
Width
=
"26"
IsEnabled
=
"False"
/>
<
Controls:ImageButton
x:Name
=
"buttonRefresh"
Grid.Column
=
"2"
Image
=
"/Controls;component/Navigator/Images/navigationRefresh.png"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Height
=
"26"
Width
=
"26"
IsEnabled
=
"False"
/>
<
Controls:ImageButton
x:Name
=
"buttonHome"
Grid.Column
=
"3"
Image
=
"/Controls;component/Navigator/Images/navigationHome.png"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Height
=
"26"
Width
=
"26"
/>
<
Controls:ImageDropdownButton
x:Name
=
"buttonUpward"
Grid.Column
=
"4"
Command
=
"{Binding NavigateUpwardCommand}"
Image
=
"/Controls;component/Navigator/Images/navigationUpward.png"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Height
=
"26"
Width
=
"38"
IsEnabled
=
"False"
Visibility
=
"Collapsed"
/>
<
Controls:ImageButton
x:Name
=
"buttonDesign"
Grid.Column
=
"6"
Text
=
"Design"
Image
=
"/Controls;component/Navigator/Images/contextDesign.png"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Height
=
"26"
Width
=
"100"
Visibility
=
"Collapsed"
>
<
Controls:StandardOpenContextMenu.ContextMenu
>
<
Controls:StandardOpenContextMenu
OpenCommand
=
"{Binding SelectDesignContextCommand}"
OpenInNewWindowCommand
=
"{Binding SelectDesignContextCommandNewWindow}"
/>
</
Controls:StandardOpenContextMenu.ContextMenu
>
</
Controls:ImageButton
>
<
Controls:ImageButton
x:Name
=
"buttonInventory"
Grid.Column
=
"7"
Text
=
"Inventory"
Image
=
"/Controls;component/Navigator/Images/contextInventory.png"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Height
=
"26"
Width
=
"100"
Visibility
=
"Collapsed"
>
<
Controls:StandardOpenContextMenu.ContextMenu
>
<
Controls:StandardOpenContextMenu
OpenCommand
=
"{Binding SelectInventoryContextCommand}"
OpenInNewWindowCommand
=
"{Binding SelectInventoryContextCommandNewWindow}"
/>
</
Controls:StandardOpenContextMenu.ContextMenu
>
</
Controls:ImageButton
>
<
Controls:ImageButton
x:Name
=
"buttonPower"
Grid.Column
=
"8"
Text
=
"Power"
Image
=
"/Controls;component/Navigator/Images/contextPower.png"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Height
=
"26"
Width
=
"100"
Visibility
=
"Collapsed"
>
<
Controls:StandardOpenContextMenu.ContextMenu
>
<
Controls:StandardOpenContextMenu
OpenCommand
=
"{Binding SelectPowerContextCommand}"
OpenInNewWindowCommand
=
"{Binding SelectPowerContextCommandNewWindow}"
/>
</
Controls:StandardOpenContextMenu.ContextMenu
>
</
Controls:ImageButton
>
<
Controls:ImageButton
x:Name
=
"buttonNetwork"
Grid.Column
=
"9"
Text
=
"Networking"
Image
=
"/Controls;component/Navigator/Images/contextNetwork.png"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Height
=
"26"
Width
=
"100"
Visibility
=
"Collapsed"
>
<
Controls:StandardOpenContextMenu.ContextMenu
>
<
Controls:StandardOpenContextMenu
OpenCommand
=
"{Binding SelectNetworkingContextCommand}"
OpenInNewWindowCommand
=
"{Binding SelectNetworkingContextCommandNewWindow}"
/>
</
Controls:StandardOpenContextMenu.ContextMenu
>
</
Controls:ImageButton
>
<
Controls:ImageButton
x:Name
=
"buttonSecurity"
Grid.Column
=
"10"
Text
=
"Security"
Image
=
"/Controls;component/Navigator/Images/contextSecurity.png"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Height
=
"26"
Width
=
"100"
Visibility
=
"Collapsed"
>
<
Controls:StandardOpenContextMenu.ContextMenu
>
<
Controls:StandardOpenContextMenu
OpenCommand
=
"{Binding SelectSecurityContextCommand}"
OpenInNewWindowCommand
=
"{Binding SelectSecurityContextCommandNewWindow}"
/>
</
Controls:StandardOpenContextMenu.ContextMenu
>
</
Controls:ImageButton
>
</
Grid
>
</
UserControl
>
using
System;
using
System.Net;
using
System.Windows;
using
System.ComponentModel;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Ink;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
using
Telerik.Windows.Controls;
namespace
ProIntegra.UDC.Frontend.GUI.Controls
{
public
class
StandardOpenContextMenu : RadContextMenu
{
RadMenuItem openItem =
new
RadMenuItem() { Header =
"Open"
};
RadMenuItem openNewItem =
new
RadMenuItem() { Header =
"Open in new window"
};
public
StandardOpenContextMenu()
{
Items.Add(openItem);
Items.Add(openNewItem);
OpenCommandProperty =
DependencyProperty.Register(
"OpenCommand"
,
typeof
(ICommand),
typeof
(StandardOpenContextMenu),
new
PropertyMetadata(
null
, OnOpenCommandChanged));
OpenInNewWindowCommandProperty =
DependencyProperty.Register(
"OpenInNewWindowCommand"
,
typeof
(ICommand),
typeof
(StandardOpenContextMenu),
new
PropertyMetadata(
null
, OnOpenInNewWindowCommandChanged));
CommandParameterProperty =
DependencyProperty.Register(
"CommandParameter"
,
typeof
(
object
),
typeof
(StandardOpenContextMenu),
new
PropertyMetadata(
null
, CommandParameterChanged));
}
public
DependencyProperty OpenCommandProperty;
public
ICommand OpenCommand
{
get
{
return
(ICommand)GetValue(OpenCommandProperty); }
set
{ SetValue(OpenCommandProperty, value); }
}
void
OnOpenCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
openItem.Command = e.NewValue
as
ICommand;
}
public
DependencyProperty OpenInNewWindowCommandProperty;
public
ICommand OpenInNewWindowCommand
{
get
{
return
(ICommand)GetValue(OpenInNewWindowCommandProperty); }
set
{ SetValue(OpenInNewWindowCommandProperty, value); }
}
void
OnOpenInNewWindowCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
openNewItem.Command = e.NewValue
as
ICommand;
}
public
DependencyProperty CommandParameterProperty;
public
object
CommandParameter
{
get
{
return
(
object
)GetValue(CommandParameterProperty); }
set
{ SetValue(CommandParameterProperty, value); }
}
void
CommandParameterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
openNewItem.CommandParameter = e.NewValue;
openItem.CommandParameter = e.NewValue;
}
}
}
0
Accepted
Hello Wojtek,
The memory leak is in your StandardContextMenu class - the Dependency Properties must be declared as static readonly. After applying this modification, there's no memory leak in the application. I'm sending you our test project for your assurance. We'd like to suggest you to use Command property of RadMenuItem and Bind your commands there, so there will be no need to create your own class, that inherits RadContextMenu. You can check an example how to use Command property of RadMenuItem in the attached project.
Hopefully this helps. Feel free to contact us in case you have any problems or concerns.
Regards,
Rosen Vladimirov
Telerik
The memory leak is in your StandardContextMenu class - the Dependency Properties must be declared as static readonly. After applying this modification, there's no memory leak in the application. I'm sending you our test project for your assurance. We'd like to suggest you to use Command property of RadMenuItem and Bind your commands there, so there will be no need to create your own class, that inherits RadContextMenu. You can check an example how to use Command property of RadMenuItem in the attached project.
Hopefully this helps. Feel free to contact us in case you have any problems or concerns.
Regards,
Rosen Vladimirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Wojtek
Top achievements
Rank 1
answered on 11 Jul 2013, 12:19 PM
Rosen, thank you for your help.
Wojtek
Wojtek