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:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
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.
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?
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();
}
}
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
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:
Best regards,
Julien G
<
Window
x:Class
=
"ListBoxTest.MainWindow"
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
>
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
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?
Is there a
telerik:ComboBoxToolTipHelper.ShowToolTipOnTrimmedText="True" that works on the RadListBox (not only the RadComboBox)?
So a :ComboBoxToolTipHelper.ShowToolTipOnTrimmedText that works on the RadListBox?
Or another way of achieving it on the RadListBox?
Background:
I tried with a behavior on the row data template but it conflicts with the drag and drop by causing exceptions during the drag and drop (but that would incur another question thread). I am just writing this to say i tried this avenue.
Right now my RadLitBox looks as follows:
<telerik:RadListBox x:Name="RLB_Source"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
ItemsSource="{Binding SourceSplitList, Mode=TwoWay}"
SelectionMode="Multiple"
telerik:ListBoxSelectedItemsBehavior.SelectedItemsSource="{Binding SelectedSourceItems}"
DisplayMemberPath="Name"
AllowDrop="True"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Visible"
Style="{StaticResource RadListBoxStyle}"
telerik:ComboBoxToolTipHelper.ShowToolTipOnTrimmedText="True"
ToolTipService.ToolTip="{Binding Text, RelativeSource={RelativeSource Self}}"
>
Because of the lines:
telerik:ComboBoxToolTipHelper.ShowToolTipOnTrimmedText="True"
ToolTipService.ToolTip="{Binding Text, RelativeSource={RelativeSource Self}}"
There is a tool tip showing the text of every RadListBox row - and not only where the text is trimmed.
How is the text trimmed? Short answer: i have a telerik:RadListBoxItem style template where text trimming is set as below:
<Setter Property="TextTrimming" Value="CharacterEllipsis"></Setter>
Here is the entire control template:
<ControlTemplate TargetType="{x:Type telerik:RadListBoxItem}">
<Border
x:Name="Bd"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="true">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
>
<ContentPresenter.Resources>
<Style TargetType="TextBlock">
<Setter Property="TextTrimming" Value="CharacterEllipsis"></Setter>
<Setter Property="TextWrapping" Value="NoWrap" />
<Setter Property="Text" Value="{Binding Name}" />
<Setter Property="ToolTipService.ToolTip" Value="{Binding Name}" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>
</Border>
</ControlTemplate>
Trimming is set on the TextBlock that appears (implicitly by Telerik) in the Contentpresenter.
The whole styling is below if relevant for answering the question:
My RadListBox has this style:
<Style x:Key="RadListBoxStyle" TargetType="{x:Type telerik:RadListBox}">
<Setter Property="AlternationCount" Value="2" />
<Setter Property="ScrollViewer.CanContentScroll" Value="True" />
<Setter Property="VirtualizingPanel.ScrollUnit" Value="Pixel" />
<Setter Property="VirtualizingPanel.VirtualizationMode" Value="Recycling" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="{StaticResource Gray}" />
<Setter Property="Background" Value="{DynamicResource White}" />
<Setter Property="SelectionMode" Value="Multiple" />
<Setter Property="FontSize" Value="12pt" />
<Setter Property="FontFamily" Value="{StaticResource SourceSansPro-Regular}" />
<Setter Property="Foreground" Value="{StaticResource Brand Default}" />
<Setter Property="Margin" Value="0,2,0,0" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="ItemContainerStyle" Value="{StaticResource DefaultDragDropRadListBoxItemStyle}" />
</Style>
In the the above style there is an ItemContainerStyle. Here it goes:
<Style x:Key="DefaultDragDropRadListBoxItemStyle" TargetType="telerik:RadListBoxItem">
<Setter Property="BorderBrush" Value="{StaticResource 'Gray Light'}" />
<Setter Property="BorderThickness" Value="0,0,0,1" />
<Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type telerik:RadListBoxItem}">
<Border
x:Name="Bd"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="true">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
>
<ContentPresenter.Resources>
<Style TargetType="TextBlock">
<Setter Property="TextTrimming" Value="CharacterEllipsis"></Setter>
<Setter Property="TextWrapping" Value="NoWrap" />
<Setter Property="Text" Value="{Binding Name}" />
<Setter Property="ToolTipService.ToolTip" Value="{Binding Name}" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Bd" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="White"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="{StaticResource 'Gray Lighter'}"></Setter>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="False" />
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsKeyboardFocused" Value="False" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Brand Light}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="False" />
<Condition Property="IsMouseOver" Value="False" />
<Condition Property="IsKeyboardFocused" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Brand Secondary}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="IsMouseOver" Value="False" />
<Condition Property="IsKeyboardFocused" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Brand Secondary}" />
<Setter Property="Foreground" Value="White" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Brand Secondary}" />
<Setter Property="Foreground" Value="White" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="IsMouseOver" Value="False" />
<Condition Property="IsKeyboardFocused" Value="False" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Brand Secondary}" />
<Setter Property="Foreground" Value="White" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="False" />
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsKeyboardFocused" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Brand Secondary}" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>