trueinteractions / wpf-autolayout Goto Github PK
View Code? Open in Web Editor NEWAuto Layout for .NET/C#/Managed C++
Auto Layout for .NET/C#/Managed C++
I was wondering if you would consider extending AddLayoutConstraint
to support Expression<TDelegate>
rather than using magic-strings for constraint declarations. This has numerous benefits, such as compile-time verification that a layout declaration is type-safe.
I haven't looked too closely at the source-code, but as you'd need to use reflection or WPF's DependencyProperty features then you'd need to use Expression<Func<...>>
instead of a naked Func<...>
.
An initial API would resemble the current AddLayoutConstraint
method, just with generic arguments for type-safety, and using named overloads for =
, <
, and >
instead of using magic-strings:
class AutoLayoutPanel
{
// A better name might be "ConstrainEquality", perhaps?
public Int32 AddEqualityConstraint<TLeft,TRight,TProperty>(
TLeft left,
Expression<Func<TLeft ,TProperty>> leftProperty,
TRight right,
Expression<Func<TRight,TProperty>> rightProperty
)
where TLeft : UIElement
where TRight : UIElement
where TProperty : IComparable<TProperty>
{
// ...
}
public Int32 AddLessThanConstraint<TLeft,TRight,TProperty>(
TLeft left,
Expression<Func<TLeft ,TProperty>> leftProperty,
TRight right,
Expression<Func<TRight,TProperty>> rightProperty
)
where TLeft : UIElement
where TRight : UIElement
where TProperty : IComparable<TProperty>
{
// ...
}
public Int32 AddGreaterThanConstraint<TLeft,TRight,TProperty>(
TLeft left,
Expression<Func<TLeft ,TProperty>> leftProperty,
TRight right,
Expression<Func<TRight,TProperty>> rightProperty
)
where TLeft : UIElement
where TRight : UIElement
where TProperty : IComparable<TProperty>
{
// ...
}
}
So the example call-sites from the README file would be rewritten as:
panel.AddEqualityConstraint( button, b => b.Left, panel, p => p.Left, multiplier: 1, constant: 0 );
panel.AddEqualityConstraint( button, b => b.Middle, panel, p => p.Middle, multiplier: 1, constant: 0 );
But these can be combined into a single AddLayoutConstraint
method if it accepts a more general Expression
argument to define the constraint:
public Int32 AddLayoutConstraint<TLeft,TRight>(
TLeft left,
TRight right,
Expression<Func<TLeft,TRight,Boolean>> constraint
)
where TLeft : UIElement
where TRight : UIElement
{
// ...
}
Thus allowing call-sites to be like this:
panel.AddLayoutConstraint( button, panel, ( b, p ) => b.Left == p.Right );
panel.AddLayoutConstraint( button, panel, ( b, p ) => b.Left * 2 + 3 == p.Right * 2 + 3 );
And this way - the constraints could be defined as C# code embedded in XAML that's evaluated when the control is initialized, thus avoiding the need for explicit AddLayoutConstraints
entirely.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.