GithubHelp home page GithubHelp logo

Comments (6)

bsivanov avatar bsivanov commented on July 20, 2024

Could you specify which example you are referring to?

from xaml-sdk.

maciz84 avatar maciz84 commented on July 20, 2024

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.

maciz84 avatar maciz84 commented on July 20, 2024

Has this been updated?

from xaml-sdk.

maciz84 avatar maciz84 commented on July 20, 2024

http://www.telerik.com/blogs/how-to-synchronize-your-ui-selected-items-with-your-data-context-using-mvvm-and-blend-behaviors-for-silverlight-and-wpf

from xaml-sdk.

maciz84 avatar maciz84 commented on July 20, 2024

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.

martinivanoff avatar martinivanoff commented on July 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.