我创建了一个IDrawable,它在GraphicsView中绘制不同的圆弧,以便创建饼图。
到目前为止没有问题,除了现在我想检测这些圆圈部分中的一个的点击或悬停。但是我没有看到任何东西可以让我轻松地做到这一点。
即使从View继承我的IDrawable来附加一个tappgesture到它似乎也不起作用(即使这样,它也不会真正回答我的问题,即能够知道哪个部分被点击了)。
public class PieChartDrawable : View, IDrawable
{
private readonly PieChart _chart;
public PieChartDrawable(PieChart chart)
{
_chart = chart;
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += OnTapped;
GestureRecognizers.Add(tapGestureRecognizer);
}
private void OnTapped(object sender, EventArgs e)
{
// Does not trigger.
}
public void Draw(ICanvas canvas, RectF dirtyRect)
{
if (_chart.Entries == null)
return;
[...]
}
}
是我做错了,还是有什么方法可以做到?(我正在寻找一个MAUI的解决方案,但我想在Xamarin Forms下工作的东西会做得很好)。
先谢谢你。
1条答案
按热度按时间sh7euo9m1#
It seams it can be a solution from the first sight:
Other one I have found at the moment the more complex to quick reuse :)
ADDED:
Invoking Events from Effects