xamarin - 使用 Syncfusion.SfChart 将滑动添加到下一个手势
问题描述
目前在我的应用程序上,当用户选择他们的“症状”时,他们会被定向到详细信息页面,该页面显示他们的症状图表,其中包含来自所选症状的填充反馈数据。
他们是我可以添加滑动手势以允许用户滑动到下一个症状图表而无需返回主要症状页面并选择症状的一种方式。
目前这是我填充图表的方式:
public async Task GetSymptomFeedback(string id)
{
SymptomFeedbackData.Clear();
symptomChart.Series.Clear();
BusyIndicator.IsRunning = true;
SymptomFeedbackData = await symptomsfeedbackmanager.getUserSymptomFeedback(id);
foreach (var FeedbackItem in SymptomFeedbackData)
{
FeedbackItem.Idusersymptomid = FeedbackItem.Id + ',' + FeedbackItem.Usersymptomid;
}
IEnumerable<SymptomFeedback> OrdreredFeedbackData = SymptomFeedbackData.OrderBy(X => X.DateTime);
LineSeries columnseries = new LineSeries
{
ItemsSource = OrdreredFeedbackData,
XBindingPath = "DateTime",
YBindingPath = "Intensity",
DataMarker = new ChartDataMarker
{
ShowLabel = true,
ShowMarker = true,
MarkerHeight = 5,
MarkerWidth = 5,
MarkerColor = Xamarin.Forms.Color.Purple
}
};
BusyIndicator.IsRunning = false;
symptomChart.PrimaryAxis.ShowTrackballInfo = true;
if (columnseries.ItemsSource != null)
{
symptomChart.Series.Add(columnseries);
}
symptomChart.ChartBehaviors.Add(new ChartTrackballBehavior());
//Sort Collection by datetime
SymptomsList.ItemsSource = OrdreredFeedbackData.Reverse();
}
解决方案
解决方案:
通过你的代码,我们可以看到你通过id
症状查询数据。所以,我猜你id
在转到detail page
from时将其作为参数传递main symptoms page
。
他们是我可以添加滑动手势以允许用户滑动到下一个症状图表而无需返回主要症状页面并选择症状的一种方式。
此外,您可以将array
所有症状的 id 传递到详细信息页面。让我们将此数组命名为symptomIdArray
.
然后将 a 添加SwipeGestureRecognizer
到您的视图中。
var DownSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Down };
var UpSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Up };
DownSwipeGesture.Swiped += OnSwiped;
UpSwipeGesture.Swiped += OnSwiped;
this.Content.GestureRecognizers.Add(DownSwipeGesture);
this.Content.GestureRecognizers.Add(UpSwipeGesture);
在 中,你可以通过andOnSwiped
获取last
或next
id ,然后你可以选择重新加载当前页面或进入新页面滑动到下一个症状图表,代码如下:symptomIdArray
currentID
public Array symptomIdArray; // ids of all symptom
public string currentID; // You selected id of current symptom
void OnSwiped(object sender, SwipedEventArgs e)
{
int index = Array.IndexOf(symptomIdArray, currentID);
switch (e.Direction)
{
case SwipeDirection.Up:
if (index ==0)
{
//first one
break;
}
string lastID = (string)symptomIdArray.GetValue(index-1);
//1.You can refresh current page with lastId
GetSymptomFeedback(lastID);
//2.You can go to a new page with lastID ID and symptomIdArray
Navigation.PushAsync(new NewPage(lastID, symptomIdArray));
break;
case SwipeDirection.Down:
// Handle the swipe
if (index == symptomIdArray.Length-1)
{
//Last one, no more
break;
}
string nextID = (string)symptomIdArray.GetValue(index+1);
//1.You can refresh current page with next currentID
GetSymptomFeedback(nextID);
//2.You can go to a new page with nextID ID and symptomIdArray
Navigation.PushAsync(new NewPage(nextID, symptomIdArray));
break;
}
}
更新:
添加SwipeGestureRecognizer
:
SfChart chart = new SfChart();
chart.Title.Text = "Chart";
//Config chart....
...
chart.Series.Add(series);
this.Content = chart;
var DownSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Down };
var UpSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Up };
DownSwipeGesture.Swiped += OnSwiped;
UpSwipeGesture.Swiped += OnSwiped;
chart.GestureRecognizers.Add(DownSwipeGesture);
chart.GestureRecognizers.Add(UpSwipeGesture);
并且onSwipe
:
void OnSwiped(object sender, SwipedEventArgs e)
{
switch (e.Direction)
{
case SwipeDirection.Up:
Console.WriteLine("up");
break;
case SwipeDirection.Down:
Console.WriteLine("down");
break;
}
}
如果您有任何问题,请告诉我。
推荐阅读
- amazon-ec2 - 使用 Vagrant 在现有 aws e2 实例上部署 yii2 高级应用程序
- perl - 在 Perl 中将散列数组转换为标量值数组
- c# - 无法将模型绑定到 DevExpress 按钮的路由值
- excel - 需要 VBA 才能在所有选项卡上工作
- c++ - 是否可以从字符串访问变量?
- node.js - 在 docker 容器内创建的目录未反映在主机上
- c++ - 将 unicode 替换为 C++ 字符串中的空格时出现分段错误错误
- python - 获取两个文本文件中的唯一行
- xcode - XCUI 测试的异步等待失败:超过 60 秒的超时,未实现预期
- jquery - 当我们点击页面的特定部分时,我想更改导航颜色如何实现