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?
P.S. Sorry for my english
CodePudding user response:
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.