讓我們擁有這個屬性:
public TCommand Read
{
get
{
return new TCommand
(
(obj) =>
{
}
);
}
}
如何在不偏離 MVVM 模式的情況下在啟動程式時啟動它?
PS對不起我的英語
uj5u.com熱心網友回復:
您可以參考答案 并執行類似的操作
<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>
如果您的應用程式中有多個視窗,則可以掛鉤Application.Startup事件。讓我知道,我會更新我的答案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/363180.html
