更新时间:2023-12-04 22:29:28
我将使用EventTrigger和InvokeCommand操作来执行此操作,以这种方式在您的视图模型ElementLoaded中调用(由于缺少更好的名称),并传递了适当的枚举内.
I would do this using EventTrigger and InvokeCommand action, that way in your view model ElementLoaded (For lack of a better name) gets called and the appropriate Enumeration gets passed in.
<Expander>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding ElementLoaded}"
CommandParameter="{x:Static local:Sections.Default}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Expander>
在ViewModel中,您将拥有ICommand类型的属性,称为ElementLoaded,然后在构造函数中将其初始化为
In your ViewModel, you will have a property of type ICommand called ElementLoaded, then in your constructor you initialize it as so
ElementLoaded = new ActionCommand(ElementLoadedMethod);
和ElementLoadedMethod可以这样
and the ElementLoadedMethod can be as so
private void ElementLoadedMethod(object section)
{
var sectionEnumVal = (Sections)section;
}
这应该是您要做的所有事情.
This should be all you have to do.