Created
December 30, 2021 17:27
-
-
Save bbenetskyy/30a8a2182c42ec31f2c920652f5693d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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