MVVM - WPF DataGrid - AutoGeneratingColumn Event -
i'm taking @ excellent toolkit laurent , have following question.
from blend 4, have added eventtrigger loaded event, in viewmodel have following:
public relaycommand rcautogeneratingcolumn { get; private set; }
in constructor have:
rcautogeneratingcolumn = new relaycommand(o => datagridautogeneratingcolumn(o));
also in viewmodel, have method wish invoked relaycommand:
private void datagridautogeneratingcolumn(object o) { datagrid grid = (datagrid)o; foreach (datagridtextcolumn col in grid.columns) { if (col.header.tostring().tolower() == "id") { col.visibility = system.windows.visibility.hidden; } } }
my xaml contains following (for datagrid):
<i:interaction.triggers> <i:eventtrigger eventname="loaded"> <galasoft_mvvmlight_command:eventtocommand command="{binding rcautogeneratingcolumn, mode=oneway}" commandparameter="{binding elementname=datagrid1, mode=oneway}"/> </i:eventtrigger> </i:interaction.triggers>
there no problem here code works fine, event used hide columns should autogeneratingcolumn event , not loaded. have used loaded event getaround.
i hoping relay event offered control that, in case, following work instead:
<i:interaction.triggers> <i:eventtrigger eventname="autogeneratingcolumn"> <galasoft_mvvmlight_command:eventtocommand command="{binding rcautogeneratingcolumn, mode=oneway}" commandparameter="{binding elementname=datagrid1, mode=oneway}"/> </i:eventtrigger> </i:interaction.triggers>
i unable autogeneratingcolumn event trigger, , i'm hoping i've overlooked , appreciate advice given!
this behaviour same gridcontrol devexpress, in loaded event triggered whereas columnspopulated event (this being equivalent of autogeneratingcolumn event) not.
devexpress offered following information regard question:
"we have reviewed question, , come interesting conclusion. looks visual tree not being built @ moment when interaction.triggers being processed"
if true, , there no other way in invoke events within viewmodel, 1 have go ahead , - using trial , error - note of datagrid events (of there on 100) can invoked in way , cannot!
one think every event available in code-behind, can reached when applying mvvm pattern.
i have searched answer cannot rule out have overlooked something, if case, please accept apologies!
during course of developing project mvvm you're going have circumstances must handle events in view's code-behind , eventtocommand plain doesn't work. find silverlight, assume question you're using wpf. it's okay event handling in view's code-behind, don't put business logic there. can leave command in view model, call directly event handler.
((yourviewmodel)this.datacontext).rcautogeneratingcolumn.execute(sender);
Comments
Post a Comment