Click here to Skip to main content
15,074,377 members
Home / Discussions / C#
   

C#

 
SuggestionRe: How to use WeakEventManager with reflection Pin
Kornfeld Eliyahu Peter24-Jan-16 1:18
professionalKornfeld Eliyahu Peter24-Jan-16 1:18 
GeneralRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre24-Jan-16 1:34
professionalSascha Lefèvre24-Jan-16 1:34 
GeneralRe: How to use WeakEventManager with reflection Pin
Kornfeld Eliyahu Peter24-Jan-16 1:38
professionalKornfeld Eliyahu Peter24-Jan-16 1:38 
GeneralRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre24-Jan-16 1:42
professionalSascha Lefèvre24-Jan-16 1:42 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 3:25
professionalKenneth Haugland24-Jan-16 3:25 
GeneralRe: How to use WeakEventManager with reflection Pin
Kornfeld Eliyahu Peter24-Jan-16 3:42
professionalKornfeld Eliyahu Peter24-Jan-16 3:42 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 3:47
professionalKenneth Haugland24-Jan-16 3:47 
AnswerRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre24-Jan-16 2:37
professionalSascha Lefèvre24-Jan-16 2:37 
I'm not familiar with WPF and PropertyDescriptor, so this might not be all you need but I think it'll get you a step further. I simplified it a bit so that I could test it in a new WPF-project. Note that you need a generic EventHandler for the AddHandler(..)-call and that you need to provide the name of the event there, not the name of the property:
C#
public MainWindow()
{
    InitializeComponent();

    object sender = this;
    WeakReference _sender = new WeakReference(sender);
    EventHandler<EventArgs> handler = (s, e) => this.Title += ".";
    string eventName = "MouseMove";

    Type unboundWEMType = typeof(WeakEventManager<,>);
    Type[] typeArgs = { _sender.Target.GetType(), typeof(EventArgs) };
    Type constructedWEMType = unboundWEMType.MakeGenericType(typeArgs);
    MethodInfo addHandlerMethod = constructedWEMType.GetMethod("AddHandler");
    addHandlerMethod.Invoke(null, new object[] { _sender.Target, eventName, handler });
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 3:11
professionalKenneth Haugland24-Jan-16 3:11 
GeneralRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre24-Jan-16 4:33
professionalSascha Lefèvre24-Jan-16 4:33 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 4:45
professionalKenneth Haugland24-Jan-16 4:45 
GeneralRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre24-Jan-16 6:14
professionalSascha Lefèvre24-Jan-16 6:14 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 17:34
professionalKenneth Haugland24-Jan-16 17:34 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 22:45
professionalKenneth Haugland24-Jan-16 22:45 
AnswerRe: How to use WeakEventManager with reflection Pin
Pete O'Hanlon24-Jan-16 7:03
mvePete O'Hanlon24-Jan-16 7:03 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 17:38
professionalKenneth Haugland24-Jan-16 17:38 
GeneralRe: How to use WeakEventManager with reflection Pin
Pete O'Hanlon24-Jan-16 21:25
mvePete O'Hanlon24-Jan-16 21:25 
AnswerRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland25-Jan-16 7:42
professionalKenneth Haugland25-Jan-16 7:42 
GeneralRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre25-Jan-16 10:28
professionalSascha Lefèvre25-Jan-16 10:28 
QuestionHow to generate Dynamic buttons in C# from Database Values? Pin
Member 1224271723-Jan-16 19:54
MemberMember 1224271723-Jan-16 19:54 
AnswerRe: How to generate Dynamic buttons in C# from Database Values? Pin
Mycroft Holmes23-Jan-16 20:13
professionalMycroft Holmes23-Jan-16 20:13 
GeneralRe: How to generate Dynamic buttons in C# from Database Values? Pin
Member 1224271723-Jan-16 20:25
MemberMember 1224271723-Jan-16 20:25 
GeneralRe: How to generate Dynamic buttons in C# from Database Values? Pin
Mycroft Holmes23-Jan-16 20:30
professionalMycroft Holmes23-Jan-16 20:30 
Questionhow to implement this code for multiple clients using c sharp Pin
Member 1061979722-Jan-16 22:32
MemberMember 1061979722-Jan-16 22:32 
AnswerRe: how to implement this code for multiple clients using c sharp Pin
OriginalGriff22-Jan-16 23:01
mveOriginalGriff22-Jan-16 23:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.