Page 1 of 1
GetLayoutClip not found.
Posted: 12 May 2023, 08:48
by DevFear
WPF to implement a custom element clip, you can override the GetLayoutClip method. But for some reason I can't find it in Noesis (I create a custom Panel). Is there an alternative to this approach or some other way to crop the elements? For example, elements inside the grid are cut off beyond its limit, and the WPF community advises using this method (it should return null).
Source:
http://drwpf.com/blog/2007/12/28/cliptoboundsmaybe/
Re: GetLayoutClip not found.
Posted: 12 May 2023, 11:27
by sfernandez
The method is available in the native API but it is not yet exposed to C#. Could you please report this in our bugtracker?
In the meantime, if you just want to clip the children of your panel with a particular geometry (inside its bounds), you can use the Clip property.
Re: GetLayoutClip not found.
Posted: 12 May 2023, 11:32
by DevFear
I want a similar implementation on WPF so that the child elements are not clipped by the container (StackPanel). How can I best achieve this in C#+ Unity?
WPF it is not clipped, since the GetLayoutClip method is implemented in the class

Re: GetLayoutClip not found.
Posted: 12 May 2023, 11:44
by DevFear
Re: GetLayoutClip not found.
Posted: 12 May 2023, 11:45
by sfernandez
Thanks for the report!
Another option if you are reimplementing the MeasureOverride/ArrangeOverride yourself, would be to inherit from the Canvas panel, which already overrides GetLayoutClip to allow children to extend outside the bounds of the panel. Could you try that?
Re: GetLayoutClip not found.
Posted: 12 May 2023, 16:58
by DevFear
Yes, it worked. After combining the Measure and Arrange logic, we got a panel that composes elements like a StackPanel, but at the same time does not cut them if they go beyond the size of the container. I attach a rough code without a scroll mechanism. (I will be glad to criticize the code)
Although the method does not look very beautiful. How long does it take you approximately to fix this kind of problem?
public class LayoutStackPanel : Canvas
{
public static DependencyProperty OrientationProperty;
static LayoutStackPanel()
{
OrientationProperty = DependencyProperty.Register(
nameof(Orientation),
typeof(Orientation),
typeof(LayoutStackPanel), new FrameworkPropertyMetadata(Orientation.Vertical, FrameworkPropertyMetadataOptions.AffectsMeasure));
}
public Orientation Orientation
{
get => (Orientation)GetValue(OrientationProperty);
set => SetValue(OrientationProperty, value);
}
protected override Size MeasureOverride(Size constraint)
{
var children = Children;
var size = default(Size);
if (Orientation == Orientation.Vertical)
{
var avialibleSize = new Size(float.PositiveInfinity, float.PositiveInfinity);
var count = children.Count;
for (int i = 0; i < count; i++)
{
var element = children[i];
if (element == null)
continue;
element.Measure(avialibleSize);
var desiredSize = element.DesiredSize;
size.Width = Math.Max(size.Width, desiredSize.Width);
size.Height += desiredSize.Height;
}
}
else
{
var avialibleSize = new Size(float.PositiveInfinity, float.PositiveInfinity);
var count = children.Count;
for (int i = 0; i < count; i++)
{
var element = children[i];
if (element == null)
continue;
element.Measure(avialibleSize);
var desiredSize = element.DesiredSize;
size.Width += desiredSize.Width;
size.Height = Math.Max(size.Height, desiredSize.Height);
}
}
return size;
}
protected override Size ArrangeOverride(Size finalSize)
{
var children = Children;
var finalRect = new Rect(finalSize);
var num = 0.0f;
if (Orientation == Orientation.Vertical)
{
var count = children.Count;
for (int i = 0; i < count; i++)
{
var element = children[i];
if (element != null)
{
finalRect.Y += num;
finalRect.Height = element.DesiredSize.Height;
num = finalRect.Height;
finalRect.Width = Math.Max(finalSize.Width, element.DesiredSize.Width);
element.Arrange(finalRect);
}
}
}
else
{
var count = children.Count;
for (int i = 0; i < count; i++)
{
var element = children[i];
if (element != null)
{
finalRect.X += num;
finalRect.Width = element.DesiredSize.Width;
num = finalRect.Width;
finalRect.Height = Math.Max(finalSize.Height, element.DesiredSize.Height);
element.Arrange(finalRect);
}
}
}
return finalSize;
}
}
Re: GetLayoutClip not found.
Posted: 15 May 2023, 11:13
by sfernandez
The code looks fine to me :)
I have included the ticket for the next 3.2.2 version. We usually release minor versions every 1-2 months, but I can't be more precise.