Notifications
Clear all

[Closed] Custom attributes .net events

Hi,

whenever I try to add event handlers to wpf controls that are defined in a custom attribute the events are not catched.

For example this works:

(
	rollout rol "rol"
	(
		dotNetControl eh "Integration.ElementHost" width:50 height:20 
		
		fn a = print "Clicked!"
		
		on rol open do
		(
			but = dotNetObject "System.Windows.Controls.Button" 
			but.content = "Press me"
			eh.child = but
			dotnet.addeventhandler but "Click" a
		)
	)
	createDialog rol
)

but if I put it inside a custom attribute def nothing happens:

(
	custAttributes.add (box()) (a = attributes test
		(
			rollout rol "rol"
			(
				dotNetControl eh "Integration.ElementHost" width:50 height:20 
				
				fn a = print "Clicked!"
				
				on rol open do
				(
					but = dotNetObject "System.Windows.Controls.Button" 
					but.content = "Press me"
					eh.child = but
					dotnet.addeventhandler but "Click" a
				)
			)
		)
	)
)

What am I missing?

5 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

(
	custAttributes.add (box()) (a = attributes test
		(
			rollout rol "rol"
			(
				--dotNetControl eh "Integration.ElementHost" width:50 height:20 
				dotnetControl sysButt "button"
				
				fn a = print "Clicked!"
				
				on rol open do
				(
					sysButt.Text="aa"
					
					--but = dotNetObject "System.Windows.Controls.Button" 
					--but.content = "Press me"
					--eh.child = but
					--dotnet.addeventhandler sysButt "Click" a
				)
				
				on sysButt mouseUp senderArg arg do
				(
					if arg.button==arg.button.left then
					(
						print "aaaa"
					)
				)
				
				
			)
		)
	)
)



(
	custAttributes.add (box()) (a = attributes test
		(
			rollout rol "rol"
			(
				--dotNetControl eh "Integration.ElementHost" width:50 height:20 
				dotnetControl sysButt "button"
				
				fn a = print "Clicked!"
				
				on rol open do
				(
					sysButt.Text="aa"
					
					--but = dotNetObject "System.Windows.Controls.Button" 
					--but.content = "Press me"
					--eh.child = but
					--dotnet.addeventhandler sysButt "Click" a
				)
				
				on sysButt mouseUp senderArg arg do
				(
					if arg.button==arg.button.left then
					(
						print "aaaa"
					)
				)
				
				
			)
		)
	)
)


Thanks, but it’s not what im after. My gui is a wpf control, hence the elementhost control.

Thanks. I ended up running the intended maxscript event code from my wpf control instead.