How do I go from missing a parameter to Loaded = ""?

I want to pass an enum parameter to Loaded=" "

so that I can easily identify the section that is being loaded without having to do name string framing.

My XAML extender:

<Expander Loaded="ExpanderLoaded" x:Name="Greeting_And_Opening_Expander" ExpandDirection="Down" IsExpanded="True" FontSize="14" FontWeight="Bold" Margin="5" BorderThickness="1" BorderBrush="#FF3E3D3D">

      

The method I want to call:

    private void ExpanderLoaded(object sender, RoutedEventArgs e, Sections section)
    {
        //Do stuff
    }

      

My Enum (this will be much more, this is just a dry run):

public enum Sections
{
    Default = 0,
    Opening = 1,
    Verify = 2
}

      

How do I go to enumeration as a parameter on boot?

+1


source to share


1 answer


I would do it with EventTrigger and InvokeCommand, this way in your view model ElementLoaded (for lack of a better name) the appropriate enum is called and passed.

<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>

      

In your ViewModel you will have a property of type ICommand called ElementLoaded and then in your constructor you initialize it as

ElementLoaded = new ActionCommand(ElementLoadedMethod);

      



and ElementLoadedMethod could be like this

    private void ElementLoadedMethod(object section)
    {
        var sectionEnumVal =  (Sections)section;
    }

      

That should be all you need to do.

+1


source







All Articles