Fix scroll issues

This commit is contained in:
qianlifeng
2013-12-27 00:39:07 +08:00
parent ece5cc7dd5
commit bdf77b2782
3 changed files with 66 additions and 11 deletions

View File

@@ -21,6 +21,8 @@ namespace WinAlfred.PluginLoader
}
public List<Result> Query(Query query)
{
try
{
string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), "query", query.RawQuery));
List<PythonResult> o = JsonConvert.DeserializeObject<List<PythonResult>>(s);
@@ -33,6 +35,13 @@ namespace WinAlfred.PluginLoader
}
return r;
}
catch (Exception)
{
throw;
}
}
public void Init()
{

View File

@@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<ScrollViewer MaxHeight="300" VerticalScrollBarVisibility="Auto">
<ScrollViewer x:Name="sv" MaxHeight="300" VerticalScrollBarVisibility="Auto">
<StackPanel x:Name="pnlContainer">
</StackPanel>

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using WinAlfred.Plugin;
@@ -89,9 +90,54 @@ namespace WinAlfred
{
if (pnlContainer.Children.Count > 0)
{
int oldIndex = GetCurrentSelectedResultIndex();
UnSelectAll();
var resultItemControl = pnlContainer.Children[index] as ResultItem;
if (resultItemControl != null) resultItemControl.Selected = true;
if (resultItemControl != null)
{
resultItemControl.Selected = true;
double scrollPosition = 0;
Point newItemBottomPoint = resultItemControl.TranslatePoint(new Point(0, resultItemControl.ActualHeight), pnlContainer);
if (index == 0)
{
sv.ScrollToTop();
return;
}
if (index == pnlContainer.Children.Count - 1)
{
sv.ScrollToBottom();
return;
}
if (index < oldIndex)
{
//move up and old item is at the top of the scroll view
if ( newItemBottomPoint.Y - sv.VerticalOffset == 0)
{
scrollPosition = sv.VerticalOffset - resultItemControl.ActualHeight;
}
else
{
return;
}
}
else
{
//move down and old item is at the bottom of scroll view
if (sv.ActualHeight + sv.VerticalOffset == newItemBottomPoint.Y - resultItemControl.ActualHeight)
{
scrollPosition = newItemBottomPoint.Y - sv.ActualHeight;
}
else
{
return;
}
}
sv.ScrollToVerticalOffset(scrollPosition);
}
}
}