WPF中“已加载"事件的行为 [英] The behavior of 'Loaded' event in WPF

查看:63
本文介绍了WPF中“已加载"事件的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候!

我对WPF中Loaded事件的行为有疑问.

Greetings!

I have a question regarding the behavior of a Loaded event in WPF.

假设我们有一个控件:

public class MyControl : ContentControl
{

    static MyControl()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl), new FrameworkPropertyMetadata(typeof(MyControl)));
    }


    void DoSomething(object sender, RoutedEventArgs e)
    {
        //...

    }

    public MyControl()
    {           
        this.Loaded += DoSomething;
    }

    public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
        "Value", typeof(string), typeof(MyControl),
        new FrameworkPropertyMetadata(default(string),
            FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal, OnValueChanged));


    private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        //some actions              
    }

    public string Value
    {
        get { return (string)GetValue(MyControl.ValueProperty); }
        set { SetValue(MyControl.ValueProperty, value); }
    }}

在触发Loaded事件时, MyControl.Value是否已经设置为它具有或不具有的Val的值?有没有预定义的

At the moment when Loaded event is fired, will the value of MyControl.Value be already set to the value of Val which it has or not? Is there any predefined behavior for the Loaded event with respect to binding?

推荐答案

我不确定.我通常要做的只是在程序中放置一个断点,例如在Loaded事件的开头,然后调试一下该断点被击中的时间.
I am not sure. What I usually do is just put a breakpoint in the program, such as at the beginning of the Loaded event, and debug then have a look when the breakpoint is hit.


这篇关于WPF中“已加载"事件的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆