我可以将哪个 xaml 元素绑定到 属性,如果需要结果 - 在启动时启动 属性?
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 模式的情况下在启动程序时启动它?
P.S。对不起我的英语
可以参考answer
并做类似
的事情
<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
事件。让我知道,我会更新我的答案。
让我们有这个属性:
public TCommand Read
{
get
{
return new TCommand
(
(obj) =>
{
}
);
}
}
如何在不偏离 MVVM 模式的情况下在启动程序时启动它?
P.S。对不起我的英语
可以参考answer 并做类似
的事情<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
事件。让我知道,我会更新我的答案。