1

During an interview, the company was asking about my use of custom controls in WPF. I have found with all of the power of the WPF way of creating a control (datatemplate, control template, styles,triggers etc... ) that having to write a custom control that overrides the OnRender method really hasn't been necessary. Later found out that most of their development has been in Winforms.

If coming at a control from a 100% WPF direction, how often is it necessary to write a customcontrol with OnRender overrides? The Winform approach is really not making use of the WPF composition technique of creating controls and it seemed like a question not based on much WPF knowledge.

Thanks Harold

11
  • 2
    In all these years using WPF, I think I've written exactly 2 custom controls. Those people know nothing about WPF. Overriding OnRender() is only a good idea if you really know what you're doing, as opposed to just trying to stuck a square peg in a round hole by treating WPF as if it were winforms. Commented Jan 5, 2015 at 14:20
  • 1
    WPF != Winforms in absolutely any way Commented Jan 5, 2015 at 14:21
  • @HighCore How can you write 2.513 custom controls? Don't answer, I have seen lot of half baked code in my little life. Commented Jan 5, 2015 at 14:22
  • 1
    @danish I fail to understand your comment Commented Jan 5, 2015 at 14:24
  • 1
    BTW, to make it perfectly clear, I've written all sorts of "custom UIs" in WPF from diagram designers to breadcrumb bars to animation timelines to a chessboard to gauge-like controls and even a compass. Not one of them required overriding OnRender(). Commented Jan 5, 2015 at 14:37

1 Answer 1

3

Good question (though a bit opinion-based) and no answers? Fixing.

If you are winforms-experienced developer, then thinking winform-way is still acceptable in wpf. For a while. This is where you may find self making mostly custom controls (containing xaml and code, or even without xaml). But the more you learn, the less you need that. Many many tasks can be completed in wpf simply because it is very flexibly. Every entity consist of something what can be customized: templates, styles, converters, behaviors or even plain event handling.

You can start with custom control and then find out what you don't really need it (or it can be downgraded to simple restyling).

When I started making first serious wpf project, there were 3 custom controls and they are still. Here is why.

  1. Outlined TextBlock. Simply because you need custom OnRender (to build and draw geometry for outline).

  2. Animated content. To apply transition animation when changing content. I could almost make it without custom control, but there is a problem - calculating animations logic when transitioning left-to-right, right-to-left, up-down or down-up. It's waaaay easy to have in one custom control. But possible with UserControl and view, not as pretty still.

  3. Graph. Simply because it's too complicated to be presented with Visual and because of performance using gdi+ gives millions of points (hundered thousands figures) to be drawn within ms.

Conclusion: it's good and useful, though way less than it was in winforms (where you simply had no other option).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your feedback... May be opinion based to a degree, but for new WPF developers coming from Winforms, this could be a huge help in guiding the proper usage of WPF. Making use of templates, styles, triggers is what in large part makes WPF WPF. So this seems to be a valid technical discussion too... Thanks, It's important to know if a prospective employer knows what the heck they are doing...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.