Comments (6)
Could you specify which example you are referring to?
from xaml-sdk.
Hi there,
I am referring to the BindingSelectedItemsFromViewModel example From A few years back. The transfer part of the code is too slow. I wouldn't complain if it was an asymc method where I could at least show a loading panel or something
from xaml-sdk.
Has this been updated?
from xaml-sdk.
from xaml-sdk.
The code i user is below:
`using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using Telerik.Windows.Controls;
using System.Collections.Specialized;
public class MySelectedItemsBindingBehavior : ViewModelBase
{
private readonly RadGridView grid = null;
private readonly INotifyCollectionChanged selectedItems = null;
private Boolean isSubscribedToEvents = false;
private static Boolean isAttached = false;
public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.RegisterAttached("SelectedItems", typeof(INotifyCollectionChanged), typeof(MySelectedItemsBindingBehavior), new PropertyMetadata(new PropertyChangedCallback(OnSelectedItemsPropertyChanged)));
public static void SetSelectedItems(DependencyObject dependencyObject, INotifyCollectionChanged selectedItems)
{
dependencyObject.SetValue(SelectedItemsProperty, selectedItems);
}
public static INotifyCollectionChanged GetSelectedItems(DependencyObject dependencyObject)
{
return (INotifyCollectionChanged)dependencyObject.GetValue(SelectedItemsProperty);
}
private static void OnSelectedItemsPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
RadGridView grid = dependencyObject as RadGridView;
INotifyCollectionChanged selectedItems = e.NewValue as INotifyCollectionChanged;
if (grid != null && selectedItems != null) {
MySelectedItemsBindingBehavior behavior = new MySelectedItemsBindingBehavior(grid, selectedItems);
behavior.Attach();
isAttached = true;
}
//If grid IsNot Nothing AndAlso selectedItems IsNot Nothing AndAlso Not isAttached Then
// Dim behavior As New MySelectedItemsBindingBehavior(grid, selectedItems)
// behavior.Attach()
// isAttached = True
//End If
}
private void Attach()
{
if (grid != null && selectedItems != null) {
Transfer(GetSelectedItems(grid) as IList, grid.SelectedItems);
SubscribeToEvents();
}
}
public MySelectedItemsBindingBehavior(RadGridView grid, INotifyCollectionChanged selectedItems)
{
this.grid = grid;
this.selectedItems = selectedItems;
}
private void ContextSelectedItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
UnsubscribeFromEvents();
Transfer(GetSelectedItems(grid) as IList, grid.SelectedItems);
SubscribeToEvents();
}
private void GridSelectedItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
UnsubscribeFromEvents();
Transfer(grid.SelectedItems, GetSelectedItems(grid) as IList);
SubscribeToEvents();
}
private void SubscribeToEvents()
{
if (!isSubscribedToEvents) {
grid.SelectedItems.CollectionChanged += GridSelectedItems_CollectionChanged;
if (GetSelectedItems(grid) != null) {
GetSelectedItems(grid).CollectionChanged += ContextSelectedItems_CollectionChanged;
}
isSubscribedToEvents = true;
}
}
private void UnsubscribeFromEvents()
{
if (isSubscribedToEvents) {
grid.SelectedItems.CollectionChanged -= GridSelectedItems_CollectionChanged;
if (GetSelectedItems(grid) != null) {
GetSelectedItems(grid).CollectionChanged -= ContextSelectedItems_CollectionChanged;
}
isSubscribedToEvents = false;
}
}
public static void Transfer(IList source, IList target)
{
if (source == null || target == null) {
return;
}
target.Clear();
foreach (object o in source) {
target.Add(o);
}
}
}`
from xaml-sdk.
Hello,
Thank you for reporting this. We just fixed it and the update will be live within the next week. In the meantime you can use the GridUtilities class from the ChartView BindingSelectedItemsToViewModel example.
Regards,
Martin Ivanov
Technical Support Engineer
from xaml-sdk.
Related Issues (20)
- RadMaskedInput IpAddress sample: broken paste functionality HOT 3
- Save button in Diagram\DiagramRibbonUI does not work HOT 2
- RadRichTextBox - Apostrophe separates word while spell checking HOT 1
- routing not working HOT 3
- TreeListView Sample doesn't work
- WPF RadDataFilter samples are missing. HOT 1
- Filter is not working in multimodel binding HOT 3
- Prism Examples HOT 7
- The data context needs to get reassigned here HOT 1
- ObjectStateManager Exception in SQLExceptionAppointment.cs HOT 1
- Binding Error in Telerik Editor User control HOT 1
- Support for image export HOT 1
- Exception Thrown in WPF Sample Project "CustomToolboxDragDrop" HOT 1
- Gridview/BindingSelectedItemsFromViewModel: Exception when DataContext is changed HOT 1
- SqlResourceType is Null on SqlResource HOT 2
- sheduleview code first for entity framework core HOT 1
- Error while removing a recurrence from the base appointment HOT 1
- RadDataForm, upgrade
- RadDocking VisualStudio Implementation with MVVM sample HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xaml-sdk.