0

Is it possible to create an Extension that will be automatic called or executed ?

.

Following situation

i have a System.Windows.Control which should execute some logic after initializing without calling this extension manual like Control.myExtension();

WiiMaxx
  • 5,322
  • 8
  • 51
  • 89
  • Do the Loaded or Initialized overrides work? More details are probably required. – kenny Mar 04 '13 at 13:28
  • What is the logic you need to be executee? also, `Loaded +=` should work. – Federico Berasategui Mar 04 '13 at 14:25
  • how shall I override the `Initialized` or `Loaded`as Extension Method because i doesn't want to write a new Class with inherit from the `System.Windows.Control` – WiiMaxx Mar 05 '13 at 07:06
  • @HighCore the logic doesn't matter at the moment i just want to know if i can do this because than i can experiment what logic work's :) – WiiMaxx Mar 05 '13 at 07:11
  • @wiimaxx the logic really matters because you shouldn't be manipulating UI elements in code in WPF in the first place. Learn MVVM, and don't try to use WPF in a winforms way. You don't need any extensions or anything like that, you need a proper ViewModel and proper Bindings for whatever you want to do. – Federico Berasategui Mar 05 '13 at 14:16
  • @HighCore so you are for example able to bind to the `Document` Property from a `RichTextBox`? without some hackish stuff like this http://stackoverflow.com/questions/2361219/bind-the-text-of-richtextbox-from-xaml – WiiMaxx Mar 05 '13 at 14:29
  • That can be resolved with a Behavior or Attached Property. My point still stands, and your question is not clear. Still, if you need to do something on `Loaded`, use `Loaded += XYZ` – Federico Berasategui Mar 05 '13 at 14:32
  • why is my question is not clear? I just want to know if it is possible to write a extension for a `UIElement` that contains some logic which will automatic executed without direct calling and adding just create a cs File and it will be called for all `UIElements` from this `Type` where ever it is (XAML or Code) – WiiMaxx Mar 05 '13 at 14:43
  • @wiimaxx [Class level Event Handler](http://stackoverflow.com/questions/5364580/class-level-event-handler-in-wpf). However, depending on what you want that for, it might or might not be a good idea. – Federico Berasategui Mar 05 '13 at 14:56
  • @HighCore this is near to them what i expected if make it as answer i will mark it as answer – WiiMaxx Mar 05 '13 at 15:18

1 Answers1

1

Converting my comment into an answer:

Class Level Event Handler

However, depending on what you want that for, it might or might not be a good idea.

Community
  • 1
  • 1
Federico Berasategui
  • 43,562
  • 11
  • 100
  • 154