I'm currently working with Windows Phone 8 application and get some problems with Long List Selector(LLS). Listbox do it by using TranslateY value:
UIElement scrollContent = (UIElement)this.targetScrollViewer.Content;
CompositeTransform ct = scrollContent.RenderTransform as CompositeTransform;
//ct.TranslateY: I need this value in Viewport's LLS to detect exactly the distance moving from the TOP
I'm try to detect pull-to-refresh with LLS but it has some flaws(using Mouse Enter, MOve, and Leave) as:
double manipulationStart = 0;
double manipulationEnd = 0;
void targetLLS_MouseEnter(object sender, MouseEventArgs e)
{
if (!this.IsRefreshing)
{
var pos = e.GetPosition(null);
manipulationStart = pos.Y;
IsMoving = false;
}
}
private void targetLLS_MouseMove(object sender, MouseEventArgs e)
{
if (!this.IsRefreshing)
{
var pos = e.GetPosition(null);
manipulationEnd = pos.Y;
IsMoving = true;
double TranslateY = manipulationEnd - manipulationStart;
if (TranslateY > this.PullThreshold)
{
this.PullDistance = 100;
this.PullFraction = 1.0;
activityState = PullDownToRefreshPanel.ReadyToReleaseVisualState;
}
else if (TranslateY > 0)
{
this.PullDistance = 100;
double threshold = this.PullThreshold;
this.PullFraction = 1;// threshold == 0.0 ? 1.0 : Math.Min(1.0, TranslateY / threshold);
activityState = PullDownToRefreshPanel.PullingDownVisualState;
}
else
{
this.PullDistance = 0;
this.PullFraction = 0;
activityState = PullDownToRefreshPanel.InactiveVisualState;
}
VisualStateManager.GoToState(this, activityState, false);
}
}
bool IsMoving = false;
void targetLLS_MouseLeave(object sender, MouseEventArgs e)
{
if (!this.IsRefreshing && IsMoving)
{
double TranslateY = manipulationEnd - manipulationStart;
EventHandler handler = this.RefreshRequested;
if (this.targetLLS.IsAtTop()
&& (activityState == PullDownToRefreshPanel.ReadyToReleaseVisualState))// TranslateY >= this.PullThreshold
{
if (handler != null)
{
IsRefreshing = true;
handler(this, EventArgs.Empty);
}
}
IsMoving = false;
}
PullDistance = 0;
PullFraction = 0;
manipulationStart = 0;
manipulationEnd = 0;
activityState = PullDownToRefreshPanel.InactiveVisualState;
//VisualStateManager.GoToState(this, activityState, false);
}
How can i do with below template:
<Style x:Key="ViewportControlStyle" TargetType="ViewportControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ViewportControl">
<ContentPresenter x:Name="ContentElement" Cursor="{TemplateBinding Cursor}" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="LongListSelectorNormalStyle" TargetType="phone:LongListSelector">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="phone:LongListSelector">
<Grid Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ScrollStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="00:00:00.5"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Scrolling">
<Storyboard>
<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="VerticalScrollBar"/>
</Storyboard>
</VisualState>
<VisualState x:Name="NotScrolling"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ViewportControl x:Name="ViewportControl" HorizontalContentAlignment="Stretch" VerticalAlignment="Top" Style="{StaticResource ViewportControlStyle}"/>
<ScrollBar x:Name="VerticalScrollBar" Grid.Column="0" Margin="4,0,4,0" Opacity="0" Orientation="Vertical" HorizontalAlignment="Right"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
My project need to implement pull function so please help me. Thanks for reading!