Hello Wu,
In this scenario, when a context menu is opened, the focus changes, and internally, the RadCardViewItem class checks if an edit operation is currently undergoing and if it is, the edit is committed.
With this in mind, I can confirm that this is not the desired behavior and as such, I have changed the status of this bug report. You can vote for it, as well as follow it, in order to get notified when its status is further changed.
Additionally, I have updated your Telerik points as a token of gratitude for reporting this behavior.
As a workaround, you can prevent the execution of the commit edit logic when the context menu is opened. To do so, create a new class that derives from the RadCardViewItem and subscribe to the ContextMenuOpening and ContextMenuclosing events. Then, override the OnIsKeyboardFocusWithinChanged method and call the base implementation of the method depending on whether the context menu is opened or not:
public class CustomCardViewItem : RadCardViewItem
{
private bool isContextMenuOpen = false;
public CustomCardViewItem()
{
this.ContextMenuOpening += CustomCardViewItem_ContextMenuOpening;
this.ContextMenuClosing += CustomCardViewItem_ContextMenuClosing;
}
private void CustomCardViewItem_ContextMenuClosing(object sender, ContextMenuEventArgs e)
{
isContextMenuOpen = false;
}
private void CustomCardViewItem_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
isContextMenuOpen = true;
}
protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
{
if (!isContextMenuOpen)
{
base.OnIsKeyboardFocusWithinChanged(e);
}
}
}
To use this type, instead of the RadCardViewItem, create a new DataTemplate and place a new instance of the custom type in it:
<Window.Resources>
<DataTemplate x:Key="CustomCardItemTemplate">
<local:CustomCardViewItem/>
</DataTemplate>
</Window.Resources>
Then, derive from the RadCardView and inside the constructor, set the ItemTemplate property of the internal LayoutControl element to the custom DataTemplate via reflection as shown below:
public class CustomCardView : RadCardView
{
public CustomCardView()
: base()
{
var layoutControl = typeof(RadCardView).GetField("layoutControl", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(this);
var itemTemplate = layoutControl.GetType().GetProperty("ItemTemplate").GetValue(layoutControl);
itemTemplate.GetType().GetProperty("ItemTemplate").SetValue(itemTemplate, (DataTemplate)App.Current.MainWindow.Resources["CustomCardItemTemplate"]);
}
}
The produced result is as follows:
With this being said, I hope the provided information will be of help to you.
Regards,
Stenly
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.