Skip to content

Instantly share code, notes, and snippets.

@bbenetskyy
Created December 30, 2021 17:27
Show Gist options
  • Save bbenetskyy/30a8a2182c42ec31f2c920652f5693d6 to your computer and use it in GitHub Desktop.
Save bbenetskyy/30a8a2182c42ec31f2c920652f5693d6 to your computer and use it in GitHub Desktop.
public class DraggableView : ContentView, IDisposable
{
public DraggableArea LimitArea { get; set; }
protected override void OnParentSet()
{
base.OnParentSet();
if (Parent is View parent)
{
parent.SizeChanged += Parent_SizeChanged;
}
}
private void Parent_SizeChanged(object sender, EventArgs e)
{
if (sender is View {Height: > 0, Width: > 0} parent)
{
LimitArea = new DraggableArea(parent.X, parent.Y,
parent.Width,
parent.Height);
}
}
public void Dispose()
{
if (Parent is View parent)
{
parent.SizeChanged -= Parent_SizeChanged;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment