网站无法发送邮件wordpress,网络技术开发有限公司,.net 建网站,设计师 推荐 网站在新闻类的APP中#xff0c;有一个经常使用的场景#xff1a;左右滑动屏幕来切换上一条或下一条新闻。 那么通常我们该使用哪种方式去实现呢#xff1f;可以参考一下Demo的实现步骤。 1#xff0c;添加Windows Phone用户自定义控件。例如#xff1a; 这里我为了演示的方便…在新闻类的APP中有一个经常使用的场景左右滑动屏幕来切换上一条或下一条新闻。 那么通常我们该使用哪种方式去实现呢可以参考一下Demo的实现步骤。 1添加Windows Phone用户自定义控件。例如 这里我为了演示的方便添加了5个用户自定义控件通常我们在做应用的时候只需要添加一个用户自定义控件结合数据绑定来承载不同新闻内容。 演示的自定义控件XAML代码也比较简单 1 UserControl x:ClassPageSliding.WindowsPhoneControl12 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation3 xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml4 xmlns:dhttp://schemas.microsoft.com/expression/blend/20085 xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/20066 mc:Ignorabled7 FontFamily{StaticResource PhoneFontFamilyNormal}8 FontSize{StaticResource PhoneFontSizeNormal}9 Foreground{StaticResource PhoneForegroundBrush}
10 d:DesignHeight480 d:DesignWidth480
11
12 Grid x:NameLayoutRoot BackgroundRed
13 TextBlock Text用户空间1/
14 /Grid
15 /UserControl 这里我只将背景颜色进行了修改和添加了一个TextBlock控件来区别我添加的5个用户自定义控件。 2切换到内容页面的XAML页面。 1 phone:PhoneApplicationPage2 x:ClassPageSliding.Solution23 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation4 xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml5 xmlns:phoneclr-namespace:Microsoft.Phone.Controls;assemblyMicrosoft.Phone6 xmlns:shellclr-namespace:Microsoft.Phone.Shell;assemblyMicrosoft.Phone7 xmlns:dhttp://schemas.microsoft.com/expression/blend/20088 xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/20069 FontFamily{StaticResource PhoneFontFamilyNormal}
10 FontSize{StaticResource PhoneFontSizeNormal}
11 Foreground{StaticResource PhoneForegroundBrush}
12 SupportedOrientationsPortrait OrientationPortrait
13 mc:Ignorabled
14 shell:SystemTray.IsVisibleTrue LoadedPhoneApplicationPage_Loaded_1
15
16 !--LayoutRoot 是包含所有页面内容的根网格--
17 Grid x:NameLayoutRoot BackgroundTransparent
18 !--ContentPanel - 在此处放置其他内容--
19 Grid x:NameContentPanel Grid.Row1 Margin12,0,12,0 ManipulationDeltaContentPanel_ManipulationDelta_1 ManipulationCompletedContentPanel_ManipulationCompleted_1
20 Grid.RenderTransform
21 CompositeTransform x:Nametransform/
22 /Grid.RenderTransform
23 /Grid
24 /Grid
25 /phone:PhoneApplicationPage 添加ManipulationDelta和ManipulationCompleted事件以及添加Grid的CompositeTransform对象。 3切换到相应.cs页面。例如 1 public partial class Solution2 : PhoneApplicationPage2 {3 ListUserControl UserControlList;4 //当前集合的显示项的索引5 int index 0;6 public Solution2()7 {8 InitializeComponent();9
10 //Demo:直接实例化UserControl的集合。
11 UserControlList new ListUserControl(){
12 new WindowsPhoneControl1(),
13 new WindowsPhoneControl2(),
14 new WindowsPhoneControl3(),
15 new WindowsPhoneControl4(),
16 new WindowsPhoneControl5()
17 };
18 }
19 private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
20 {
21 //Demo:首次加载集合的第一项
22 this.ContentPanel.Children.Add(UserControlList[0]);
23 }
24
25 private void ContentPanel_ManipulationDelta_1(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
26 {
27 //页面ContentPanel容器只能左右拖动不能上下拖动。
28 transform.TranslateX e.DeltaManipulation.Translation.X;
29 transform.TranslateY 0;
30 }
31
32 private void ContentPanel_ManipulationCompleted_1(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
33 {
34 //ContentPanel容器总转换的线性运动的X坐标值〉100
35 if (e.TotalManipulation.Translation.X 100)
36 {
37 //加载前一项
38 if (this.index 0)
39 {
40 MessageBox.Show(当前为第一项);
41 }
42 else
43 {
44 index - 1;
45 //加载前一条数据
46 this.ContentPanel.Children.Clear();
47 this.ContentPanel.Children.Add(UserControlList[index]);
48 }
49 }
50 //ContentPanel容器总转换的线性运动的X坐标值〈-100
51 else if (e.TotalManipulation.Translation.X -100)
52 {
53 //加载后一项
54 if(this.index4)
55 {
56 MessageBox.Show(当前为最后一项);
57 }
58 else
59 {
60 index 1;
61 //加载后一条数据
62 this.ContentPanel.Children.Clear();
63 this.ContentPanel.Children.Add(UserControlList[index]);
64 }
65 }
66 //切换之后恢复ContentPanel容器的X偏移量.
67 transform.TranslateX 0;
68 }
69 } 通过以上的操作我们就可以左右滑动切换刚才定义的5个不同用户自定义控件了。 另外我们也可以参考该文章windows phone开发学习--自己实现一个Gallery control 该文章的实现方式主要是一次加载3个不同的用户控件通过左右滑动来加载3个不同的用户自定义控件。转载于:https://www.cnblogs.com/wzk89/archive/2013/05/24/3097325.html