Monday, 15 April 2013

c# - using an event to command trigger inside a style -



c# - using an event to command trigger inside a style -

i trying utilize mvvm lite toolkit bind event command within style.

i have style:

<style xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:controls='clr-namespace:system.windows.controls;assembly=system.windows.controls' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:d='http://schemas.microsoft.com/expression/blend/2008' xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' xmlns:ig='http://schemas.infragistics.com/xaml' xmlns:i='http://schemas.microsoft.com/expression/2010/interactivity' xmlns:command='clr-namespace:galasoft.mvvmlight.command;assembly=galasoft.mvvmlight.extras.wpf4' targettype='ig:eventspan'> <setter property='template'> <setter.value> <controltemplate targettype='ig:eventspan'> <grid margin='0,2,0,2'> <i:interaction.triggers> <i:eventtrigger eventname='mouseenter'> <command:eventtocommand command='{binding eventspan_mouseenter1}' commandparameter='{binding relativesource={relativesource ancestortype={x:type ig:eventspan}}}'/> </i:eventtrigger> <i:eventtrigger eventname='mouseleave'> <command:eventtocommand command='{binding eventspan_mouseleave1}' commandparameter='{binding relativesource={relativesource ancestortype={x:type ig:eventspan}}}'/> </i:eventtrigger> </i:interaction.triggers> <rectangle radiusx='0' radiusy='0' fill='{templatebinding fill}' stroke='{templatebinding stroke}' strokethickness='0' height='0' margin='0, 0, 0, 0' verticalalignment='top' /> </grid> </controltemplate> </setter.value> </setter> </style>

and illustration of code behind is:

private relaycommand<string> _eventspan_mouseenter; public relaycommand<string> eventspan_mouseenter1 { { homecoming _eventspan_mouseenter ?? (_eventspan_mouseenter = new relaycommand<string>( sender => { mouseoverlayer = sender; })); } }

but command never fires , cannot work out why?

ps. reason libraries referenced in styles because style loaded dynamically code behind. legacy code trying convert mvvm.

so there 2 problems way had bound before. firstly main reason style had no datacontext. , apparently didnt inherit datacontext template implementing style. , command parameter incorrect.

commandparameter='{binding relativesource={relativesource ancestortype={x:type ig:eventspan}}}'

was binding relaycommand expecting string parameter , crashed. hence right commandparameter was

commandparameter='{binding path=evententry.series.tag, relativesource={relativesource ancestortype={x:type ig:eventspan}}}'

c# wpf mvvm mvvm-light

No comments:

Post a Comment