我希望能够在Loaded=" "上传递枚举参数,这样我就可以轻松地识别正在加载的节,而不必对名称进行字符串欺骗。
我的Expander XAML:
<Expander Loaded="ExpanderLoaded" x:Name="Greeting_And_Opening_Expander" ExpandDirection="Down" IsExpanded="True" FontSize="14" FontWeight="Bold" Margin="5" BorderThickness="1" BorderBrush="#FF3E3D3D">我希望它调用的方法:
private void ExpanderLoaded(object sender, RoutedEventArgs e, Sections section)
{
//Do stuff
}我的枚举(它会大得多,这只是一次测试运行):
public enum Sections
{
Default = 0,
Opening = 1,
Verify = 2
}如何在加载时将枚举作为参数传递?
发布于 2015-05-28 02:21:04
我将使用EventTrigger和InvokeCommand操作来实现这一点,这样就可以在视图模型中调用ElementLoaded (因为没有更好的名称),并传入适当的枚举。
<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中,您将拥有一个名为ElementLoaded的ICommand类型的属性,然后在您的构造函数中将其初始化为
ElementLoaded = new ActionCommand(ElementLoadedMethod);并且ElementLoadedMethod可以是这样的
private void ElementLoadedMethod(object section)
{
var sectionEnumVal = (Sections)section;
}这应该是您要做的全部工作。
https://stackoverflow.com/questions/30488770
复制相似问题