A memory leak occurs when you remove the RadVirtualKeyboard from the view. The control's reference is hold by an internal static collection, which prevents it from being garbage collected.
To work this around, you can use reflection to access the NativeMethods.callbacks static collection and clear it. If you have the SynchronizeCultureWithSystem propety set to True (the default value) you should also cancel the task listens for system culture change.
private void RemoveKeyboardFromView(RadVirtualKeyboard keyboard)
{
var assembly = Assembly.LoadFrom("Telerik.Windows.Controls.Navigation.dll");
var type = assembly.GetType("Telerik.Windows.Controls.VirtualKeyboard.NativeMethods");
var field = type.GetField("callbacks", BindingFlags.Static | BindingFlags.NonPublic);
var cancelationTokenFieldInfo = typeof(RadVirtualKeyboard).GetField("systemCultureTrackingCancellationTokenSource", BindingFlags.Instance | BindingFlags.NonPublic);
var keyPressedMethodInfo = typeof(RadVirtualKeyboard).GetMethod("KeyPressed", BindingFlags.Instance | BindingFlags.NonPublic);
var keyPressedCallback = (Action<int, bool>)keyPressedMethodInfo.CreateDelegate(typeof(Action<int, bool>), keyboard);
var callbacks = (List<Action<int, bool>>)field.GetValue(null);
callbacks.Remove(keyPressedCallback);
var cancelationToken = cancelationTokenFieldInfo.GetValue(keyboard) as CancellationTokenSource;
cancelationToken.Cancel();
}
The Header property setting is replaced with a default value when the RadVirtualKeyboardWindowAutomationPeer is created. This happens on environments where the automation peers creation kicks-in. Like, on touch devices, when a screen narrator application is used, on visual elements inspection with some tools (like UISpy or Snoop) or any other automation testing that requires automation peers.
In that case, instead of the user defined Header value, the window's header is replaced with "RadVirtualKeyboardWindow" string.
To work this around, disable the automation peers:
public partial class App : Application
{
public App()
{
AutomationManager.AutomationMode = AutomationMode.Disabled;
this.InitializeComponent();
}
}
Our company would like to use in a greenfield project this new UI component.
On our machine, in both our sample projects and even running your official WPF Demo App, the virtualkeyboard component does not render its buttons correctly.
This is our sample xaml:
<Window x:Class="TelerikWpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
Title="MainWindow" Height="350" Width="525">
<Grid>
<telerik:RadVirtualKeyboard DefaultKeyboardLayout="Compact" HorizontalAlignment="Stretch" />
</Grid>
</Window>
In the attachment you can see how the virtualkeyboard renders ootb. Are we missing something?