I am looking for examples and experience of using fluent interface to define simple Dialog Boxes (and other UI elements).
(I may need to add support for custom Dialog Boxes to an in-house programming language and I think a fluent interface may be the best way of doing it)
The UI system will be build on Winforms OR WPF if that effects your answers.
What if the interface is not fluent and I changed the question to just a “a simple to use (and read) API..” that does not depend on the use of a “drag and drop” UI designer.
I think the result will be fluent to some extend, e.g
Textbox(“name”). Labelled(“Person
Name”). Column(1)Textbox(“notes”). Labelled(“Notes”).
Multiline(4). Column(1).ToColumn(3)
However the interface does not have to be a single line
This “How to make Databinding type safe and support refactoring”
gives a good starting point for a fluent interface for databinding.
The examples given so far do nothing to reduce the complexity of the task; they only trade one syntax for another (almost equally verbose) one. If you invest the time to create a fluent interface, leverage it to actually improve the expressiveness of your API instead of just jiggling syntactic sugar. Raise the level of abstraction from the default primitives (buttons, modalities,…) to templates, visual inheritance chains and behaviors.
I haven’t totally thought this through yet, but something along the lines of:
or