[英]Which xaml-element i can bind to the property, if desired result - start the property at startup?
让我们有这个属性:
public TCommand Read
{
get
{
return new TCommand
(
(obj) =>
{
}
);
}
}
如何在不偏离 MVVM 模式的情况下在启动程序时启动它?
PS对不起我的英语
您可以参考答案并执行类似的操作
<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>
如果您的应用程序中有多个 windows,则可以挂钩Application.Startup
事件。 让我知道,我会更新我的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.