簡體   English   中英

如果需要結果,我可以將哪個 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 模式的情況下在啟動程序時啟動它?

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM