/
ChatListRenderer.cs
26 lines (24 loc) · 971 Bytes
/
ChatListRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System.Collections.Specialized;
using System.Linq;
using Crosschat.Client.Views.Controls;
using Crosschat.Client.WinPhone.CustomRenderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.WinPhone;
[assembly: ExportRenderer(typeof(ChatListView), typeof(ChatListRenderer))]
namespace Crosschat.Client.WinPhone.CustomRenderers
{
public class ChatListRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
var control = Control;
if (control != null && control.ItemsSource is INotifyCollectionChanged)
{
//auto-scroll on ItemsSource change
((INotifyCollectionChanged)control.ItemsSource).CollectionChanged += (sender, args) =>
Dispatcher.BeginInvoke(() => control.ScrollTo(control.ItemsSource.OfType<object>().FirstOrDefault()));
}
}
}
}