[WPF] Fix scrolling in ListView and TreeView

This commit is contained in:
Lluis Sanchez 2012-03-30 02:26:03 +02:00
Родитель a1e7e2c92b
Коммит 1e5b52c771
5 изменённых файлов: 70 добавлений и 9 удалений

Просмотреть файл

@ -21,7 +21,7 @@ namespace Samples
var png = Image.FromResource (typeof(App), "class.png");
for (int n=0; n<10; n++) {
for (int n=0; n<100; n++) {
var r = store.AddRow ();
store.SetValue (r, icon, png);
store.SetValue (r, name, "Value " + n);

Просмотреть файл

@ -33,6 +33,7 @@ using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Input;
using SW = System.Windows;
using SWC = System.Windows.Controls;
using SWM = System.Windows.Media;
using SD = System.Drawing;
using SDI = System.Drawing.Imaging;
@ -388,5 +389,37 @@ namespace Xwt.WPFBackend
if (type == DataFormats.FileDrop) return TransferDataType.Uri;
return TransferDataType.FromId (type);
}
// Scrollbar visibility
public static SWC.ScrollBarVisibility ToWpfScrollBarVisibility (ScrollPolicy policy)
{
switch (policy) {
case ScrollPolicy.Always:
return SWC.ScrollBarVisibility.Visible;
case ScrollPolicy.Automatic:
return SWC.ScrollBarVisibility.Auto;
case ScrollPolicy.Never:
return SWC.ScrollBarVisibility.Hidden;
default:
throw new NotSupportedException ();
}
}
public static ScrollPolicy ToXwtScrollPolicy (SWC.ScrollBarVisibility visibility)
{
switch (visibility) {
case SWC.ScrollBarVisibility.Auto:
return ScrollPolicy.Automatic;
case SWC.ScrollBarVisibility.Visible:
return ScrollPolicy.Always;
case SWC.ScrollBarVisibility.Hidden:
return ScrollPolicy.Never;
default:
throw new NotSupportedException ();
}
}
}
}

Просмотреть файл

@ -49,8 +49,22 @@ namespace Xwt.WPFBackend
protected override System.Windows.Size MeasureOverride (System.Windows.Size constraint)
{
var s = base.MeasureOverride (constraint);
return Backend.MeasureOverride (constraint, s);
// This line is commented because it breaks listview scrolling
// We have to find a solution because the current implementation is not fully correct
// var s = base.MeasureOverride (constraint);
var s = new System.Windows.Size (0, 0);
if (ScrollViewer.GetHorizontalScrollBarVisibility (this) != ScrollBarVisibility.Hidden)
s.Width = 0;
if (ScrollViewer.GetVerticalScrollBarVisibility (this) != ScrollBarVisibility.Hidden)
s.Height = SystemParameters.CaptionHeight;
s = Backend.MeasureOverride (constraint, s);
return s;
}
protected override System.Windows.Size ArrangeOverride (System.Windows.Size arrangeBounds)
{
return base.ArrangeOverride (arrangeBounds);
}
public static readonly DependencyProperty SelectedIndexesProperty = DependencyProperty.Register (

Просмотреть файл

@ -44,18 +44,26 @@ namespace Xwt.WPFBackend
ListView.View = this.view;
}
// TODO
public Xwt.ScrollPolicy VerticalScrollPolicy
{
get { return Xwt.ScrollPolicy.Automatic; }
set { }
get {
return DataConverter.ToXwtScrollPolicy (ScrollViewer.GetVerticalScrollBarVisibility (ListView));
}
set {
ScrollViewer.SetVerticalScrollBarVisibility (ListView, DataConverter.ToWpfScrollBarVisibility (value));
}
}
// TODO
public Xwt.ScrollPolicy HorizontalScrollPolicy
{
get { return Xwt.ScrollPolicy.Automatic; }
set { }
get
{
return DataConverter.ToXwtScrollPolicy (ScrollViewer.GetHorizontalScrollBarVisibility (ListView));
}
set
{
ScrollViewer.SetHorizontalScrollBarVisibility (ListView, DataConverter.ToWpfScrollBarVisibility (value));
}
}
public bool HeadersVisible {

Просмотреть файл

@ -31,6 +31,7 @@ using Xwt.Backends;
using Xwt.WPFBackend.Utilities;
using System.Windows;
using SWC=System.Windows.Controls;
using System.Windows.Controls;
namespace Xwt.WPFBackend
{
@ -253,6 +254,11 @@ namespace Xwt.WPFBackend
protected override System.Windows.Size MeasureOverride (System.Windows.Size constraint)
{
var s = base.MeasureOverride (constraint);
if (ScrollViewer.GetHorizontalScrollBarVisibility (this) != ScrollBarVisibility.Hidden)
s.Width = 0;
if (ScrollViewer.GetVerticalScrollBarVisibility (this) != ScrollBarVisibility.Hidden)
s.Height = SystemParameters.CaptionHeight;
s = Backend.MeasureOverride (constraint, s);
return Backend.MeasureOverride (constraint, s);
}
}