ainila 发表于 2018-6-15 10:58:38

Windows Phone 内容滑动切换实现

public partial>
{  
List<UserControl> UserControlList;
  
//当前集合的显示项的索引
  
int index = 0;
  
public Solution2()
  
{
  
InitializeComponent();
  
//Demo:直接实例化UserControl的集合。
  
UserControlList = new List<UserControl>(){
  
new WindowsPhoneControl1(),
  
new WindowsPhoneControl2(),
  
new WindowsPhoneControl3(),
  
new WindowsPhoneControl4(),
  
new WindowsPhoneControl5()
  
};
  
}
  
private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
  
{
  
//Demo:首次加载集合的第一项
  
this.ContentPanel.Children.Add(UserControlList);
  
}
  
private void ContentPanel_ManipulationDelta_1(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
  
{
  
//页面ContentPanel容器只能左右拖动不能上下拖动。
  
transform.TranslateX += e.DeltaManipulation.Translation.X;
  
transform.TranslateY = 0;
  
}
  
private void ContentPanel_ManipulationCompleted_1(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
  
{
  
//ContentPanel容器总转换的线性运动的X坐标值〉=100
  
if (e.TotalManipulation.Translation.X >= 100)
  
{
  
//加载前一项
  
if (this.index == 0)
  
{
  
MessageBox.Show("当前为第一项");
  
}
  
else
  
{
  
index -= 1;
  
//加载前一条数据
  
this.ContentPanel.Children.Clear();
  
this.ContentPanel.Children.Add(UserControlList);
  
}
  
}
  
//ContentPanel容器总转换的线性运动的X坐标值〈=-100
  
else if (e.TotalManipulation.Translation.X <= -100)
  
{
  
//加载后一项
  
if(this.index==4)
  
{
  
MessageBox.Show("当前为最后一项");
  
}
  
else
  
{
  
index += 1;
  
//加载后一条数据
  
this.ContentPanel.Children.Clear();
  
this.ContentPanel.Children.Add(UserControlList);
  
}
  
}
  
//切换之后恢复ContentPanel容器的X偏移量.
  
transform.TranslateX = 0;
  
}
  
}
页: [1]
查看完整版本: Windows Phone 内容滑动切换实现