GetLayoutClip not found.
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/
Source: http://drwpf.com/blog/2007/12/28/cliptoboundsmaybe/
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: GetLayoutClip not found.
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.
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.
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: GetLayoutClip not found.
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?
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.
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?
Although the method does not look very beautiful. How long does it take you approximately to fix this kind of problem?
Code: Select all
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;
}
}
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: GetLayoutClip not found.
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.
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.
Who is online
Users browsing this forum: No registered users and 15 guests