Telerik Forums
UI for WPF Forum
1 answer
13 views
Hello!

I have exactly this problem reported on this post: https://www.telerik.com/forums/selecteditem-reset-when-unloading but using RadListBox.

Do you know of any solutions other than setting DataContext explicitly? This workaround worked on some controls but not on others.
Martin Ivanov
Telerik team
 answered on 26 May 2025
3 answers
1.0K+ views

Hi, 

I have some struggle with context menu binding. The problem is that I cant bind Command from  CustomerViewModel  to a RadMenuItem in a Context menu.

Here is my code:

public class CustomerViewModel : ViewModelBase
{
    private ObservableCollection<Customer> _customers;
 
    public ICommand AddCom { get; set; }
    public ICommand DelCom { get; set; }
    public CustomerViewModel()
    {
        AddCom = new DelegateCommand(Add);
        DelCom = new DelegateCommand(Del);
    }
 
    private void Add(object o)
    {
        Customers.Add(new Customer(){Id=Customers.Count,
                Name="Customer "+ Customers.Count.ToString()} );
        OnPropertyChanged(() => this.Customers);
    }
    private void Del(object o)
    {
        Customers.Remove((Customer) o);
        OnPropertyChanged(() => this.Customers);
    }
     
    public ObservableCollection<Customer> Customers
    {
        get => this._customers;
        set
        {
            if (this._customers == value) return;
            this._customers = value;
            this.OnPropertyChanged(() => this.Customers);
        }
    }
}

and XAML

<Window x:Class="CustomListBoxDragDropBehavior.MainWindow"
        xmlns:local="clr-namespace:CustomListBoxDragDropBehavior"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525" >
    <d:Window.DataContext>
        <local:CustomerViewModel/>
    </d:Window.DataContext>
    <Window.Resources>
        <telerik:RadContextMenu x:Key="Menu">
            <telerik:RadMenuItem Header="Add customer" Command="{Binding ??? }" />
            <telerik:RadMenuItem Header="Remove customer" Command="{Binding ???}"
                   CommandParameter=" ??? "/>/>
        </telerik:RadContextMenu>
        <Style x:Key="ListBoxItem" TargetType="telerik:RadListBoxItem">
            <Setter Property="telerik:RadContextMenu.ContextMenu" Value="{StaticResource Menu}"/>
        </Style>
    </Window.Resources>
 
    <Grid >
        <telerik:RadListBox ItemContainerStyle="{StaticResource ListBoxItem}"
                            ItemsSource="{Binding Customers, Mode=TwoWay}"
                            DisplayMemberPath="Name"
                            >
        </telerik:RadListBox>
    </Grid>
</Window>

I tried few combination like 

<telerik:RadMenuItem Header="Item" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=DataContext.AddCom }" />

with no success. Also I need to pass current customer to a DelCom as parameter.

Please advise.

 

fabrizio
Top achievements
Rank 1
Iron
 updated answer on 03 Mar 2025
0 answers
29 views

Hi,

As mentioned above, I would like to add a button that allows me to select which columns of the radgridview that I want to show. May I seek your advise on this?

Lim
Top achievements
Rank 1
Iron
 asked on 26 Feb 2025
0 answers
62 views

Hello, 

im trying to set the focus on a ListBoxItem so the User can navigate to the next Index by pressing the down button.

Our current implementation is that the focus is set on the RadListBox itself and not on the item but you need to double press down to get the second item.

Is there some way to set the focus on the items itself rather than the ListBox?

I already tried something like this but this is not working.
 if (ListBox.SelectedItem != null)
 {
     var item = ListBox.ItemContainerGenerator.ContainerFromIndex(ListBox.SelectedIndex);
     if(item != null)
     {
         ((RadListBoxItem)item).Focus();
     }
     else
     {
         ListBox.Focus();
     }
 }

Marvin
Top achievements
Rank 1
 asked on 28 Mar 2024
1 answer
170 views
Hi, 

I'm trying to use your DragDropManager to be able to reorder my lists as I wish. 

And I have to congratulate you because it's very easy to use when you just want to reorder a list.

Unfortunately, I would like to execute a method after each drag and drop action.

I tried to bind a command on the Drop event but the list order wasn't modified yet. 

So I found the telerik:DragDropManager.DragDropCompleted which seemed perfect but I didn't succeed to use it.

I tried to respect MVVM pattern with the telerik:EventToCommandBehavior, System.Windows.Interactivity.EventTrigger but it didn't work.

I also tried to use it in the code-behind (xaml.cs) but nothing works.


Can you help me to understand what's the problem ?

And can you also help me to find a way to resolve my problem within respect the MVVM pattern ?


Thanks in advance for your time and your answer.
Martin Ivanov
Telerik team
 answered on 28 Jul 2023
0 answers
128 views

Hi,

Maybe I found a strange bug in RadListBox (2023 R1). I guess it is very hard to reply because I use it in a very complex way but maybe you could figure out the cause of problem.
My radlistbox is bound to a ObservableCollection of objects (we can name it List), and it is refreshed every time the user change the tab in raddocking. RadListbox is only one, while tab is multiple. It works in this context.

In my application I can "close the project", operation that implies the reset of every controls in the window, List is now clear, but the instance is still live.
I can "reopen the project" and the original tabs. In this context in many combination of tab open and close I get the following exception:

NsModules.App::AppDomainUnhandledException - System.ArgumentException: An item with the same key has already been added. Key: DeltaOhm.NsModules.Model.NsCursor
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Telerik.Windows.Automation.Peers.RadListBoxAutomationPeer.CreateItemAutomationPeer(Object item)
   at System.Windows.Automation.Peers.ItemsControlAutomationPeer.GetChildrenCore()
   at System.Windows.Automation.Peers.AutomationPeer.EnsureChildren()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateChildrenInternal(Int32 invalidateLimit)
   at System.Windows.Automation.Peers.ItemsControlAutomationPeer.UpdateChildren()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.ContextLayoutManager.fireAutomationEvents()
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at NsModules.App.Main()

I replaced RadListBox with system ListBox and the problem disappeared

Thank you

Luigi

Luigi
Top achievements
Rank 3
Bronze
Iron
Iron
 updated question on 31 Mar 2023
1 answer
110 views

Hello,

 

We experienced very slow startup times for our WPF Telerik app recently (~50 seconds).

I have attached a project to replicate the problem. It only happens sometimes, but when it does, the simple demo app takes up to 30 seconds to boot up (not counting build time). This happens with and without the debugger.

In the screenshot "telerik_debug_logs.png", we can see that the app decides to load 30+ Telerik DLLs, almost none of which are necessary for this tiny app. Loading all these DLLs takes time, most notably the first one (Telerik.Window.Controls.dll) which seems to take 5.9 seconds on it's own.

Interestingly enough, when we comment out the drag drop animation storyboard, only 2 of Telerik DLLs are loaded. See screenshot "telerik_debug_logs_NO_ANIMATION.png".

 

Is this expected behavior ? Is there something I can to to mitigate the long startup times ?

 

Config:

  • .NET 7 (also tested in .NET 6)
  • Telerik UI for WPF (XAML) v2023.1.117
  • VS 2022 v17.5.2

 

 

Best regards,

Julien G

 

 

 

Vladimir Stoyanov
Telerik team
 answered on 23 Mar 2023
3 answers
306 views
Dear Telerik Team,
We've bumped into next issue. There is RadListBox which exposes CollectionViewSource with grouping.
When user scrolls the listbox up and down (with a mouse wheel or just dragging the thumb), vertical scrollbar changes it's length.
We've ensured that this bug is being reproduced with every Telerik theme set up. And everything is fine if we switch to default WPF ListBox control. 

Here's the code snippet :

<Window x:Class="ListBoxTest.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" Width="1024" Height="768">
     
    <Window.Resources>
        <CollectionViewSource x:Key="Results" Source="{Binding}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Category" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
    </Window.Resources>
     
    <DockPanel DataContext="{Binding}">
        <telerik:RadListBox Margin="0 0 10 10"
                ItemsSource="{Binding Source={StaticResource Results}}"
                SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
 
            <telerik:RadListBox.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Margin="10 10 0 10"
                                        FontWeight="Bold"
                                        Foreground="LightBlue"
                                        Visibility="{Binding Name}"
                                        Text="{Binding Path=Name}"/>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </telerik:RadListBox.GroupStyle>
 
            <telerik:RadListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <StackPanel Margin="5" VerticalAlignment="Center">
                            <TextBlock FontWeight="Bold"><Run Text="{Binding FirstName, Mode=OneWay}" /> <Run Text="{Binding LastName, Mode=OneWay}" /></TextBlock>
                            <TextBlock>Email: <Run Text="{Binding Email, Mode=OneWay}" /></TextBlock>
                            <TextBlock>Phone: <Run Text="{Binding PhoneNumber, Mode=OneWay}" /></TextBlock>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </telerik:RadListBox.ItemTemplate>
        </telerik:RadListBox>
    </DockPanel>
</Window>


Is there any way to fix this behavior? Any help will be appreciated.

Best Regards, Stanislav


Kay
Top achievements
Rank 1
Iron
 answered on 30 Jan 2023
1 answer
108 views

I have one parent type “Aa” inherit from “Telerik.Windows.Controls.ScheduleView.Appointment”, with two inherited types “Bb” and “Cc”. while each one has different properties implementation.

 

I have a RadScheduleView which it’s AppointmentsSource bounded to my ViewModel collection of parent type “Aa” (ObservableCollection<Aa>)

 

I also have two baskets, first one is a list of “Bb” items while the second one is a list of “Cc” items.

 

I can drag any item from each basket (“Aa” or “Bb”) and drop them on the ScheduleView so a new Appointment is created.

 

My problem is that the newly created appointment is always created from parent type “Aa” no matter which basket I selected to drag.

 

I want it to work according to the origin dragged item type so the new appointment will match the type “Bb” or “Cc”.

 

 

I Prepared a Sample code you can see here:

 

https://gist.github.com/EfiNadell/bcc10a8f93b210b7eaf626e67cf459a2

Dilyan Traykov
Telerik team
 answered on 25 Jan 2023
1 answer
196 views

We have a RadListBox bound to a ObservableCollection of models.  We would like sort them based on a property.  The property value can also change.  Is there any way to sort them?

What we are trying to do is create a "mover" to rank items, is a RadListBox not the best choice?

Martin Ivanov
Telerik team
 answered on 02 Dec 2022
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?