开发者

Best approch for creating Base control

I am looking for a solution for this scenario -

I need to implement a feature to allow user to add various controls to canvas(WPF, custom and third party ) and then select any one of them and modify some properties in PropertyGrid(changes needs 开发者_开发百科to be reflected in UI).

I don't want to expose all the properties of any control only some of them(relevant to end user); apart from this there are some properties which will be common for all controls e.g. Title, Value(Value will be bound to some property of a control, say Text of TextBox and Content of Label) etc.

I am thinking of putting all the common properties at one place.

Things I am confused about -

  1. How to create such base class, whether to use UserControl or Custom Control for this?

  2. How will the binding work between Control, base class properties and PropertyGrid?

  3. What type of object will I expose to PropertyGrid?

Any idea on what approach should be followed in this case, any kind of input will really be helpful.


Perhaps you should start from this book WPF Control Development Unleashed.

1) Custom control should be more appropriate.
2) For binding - You should learn more about TemplateBinding, RelativeSources binding etc.,
3) Your property can be either normal property or dependency property. Both, of them will be available for you in property grid to edit. If your exposed property is bindable, obviously, it should be dp. If you expose a property (means a property with public access specifier) it would be enough to get it available in the property grid.

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜