简体   繁体   中英

Which xaml-element i can bind to the property, if desired result - start the property at startup?

Let us have this property:

        public TCommand Read
        {
            get
            {
                return new TCommand
                (
                    (obj) =>
                    {
                        
                    }
                );
            }
        }

How to launch this on start the program without deviating from the MVVM pattern?

PS Sorry for my english

You can refer to answer and do something like

<Window x:Class="YourApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        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"
        Title="MainWindow"
        mc:Ignorable="d"
        xmlns:local="clr-namespace:YourApplication"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        Height="450" Width="800">
    <Window.DataContext>
        <local:MainViewModel />
    </Window.DataContext>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <i:InvokeCommandAction Command="{Binding Read}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Window>

If you have a multiple windows in your application, you can hook into Application.Startup event. Let me know and I'll update my answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM