开发者

WPF: Visibility binding, event = null

开发者 https://www.devze.com 2023-03-07 20:57 出处:网络
I have the following code: public event EventHandler LoadingControlVisibilityChanged; public Visibility LoadingControlVisibility

I have the following code:

    public event EventHandler LoadingControlVisibilityChanged;
    public Visibility LoadingControlVisibility
    {
        get { return _LoadingControlVisibility; }
        set
        {
            _LoadingControlVisibility = value;
            if (LoadingControlVisibilityChanged != null)
                LoadingControlVisibilityChanged(this, EventArgs.Empty);
        }
    }

<Label x:Name="loading" Visibility="{Binding Path=LoadingControlVisibility, Mode=OneWay}" Content="No Devices Detected!" FontFamily="{DynamicResource AppFont}" HorizontalAlignment="Left" Margin="110,0,0,0" FontSize="21.333" />

The first time the binding work, but after I change the LoadingControlVisibility nothing happens, after debug I notice that the event = null. Please help me solve this problem.

my text property works with no problems:

    public event EventHandler UUidChanged;
    public开发者_运维技巧 string UUid
    {
        get { return _uuid; }
        set
        {
            _uuid = value;
            if (UUidChanged != null) UUidChanged(this, EventArgs.Empty);
        }
    }
<TextBox Text="{Binding Path=UUid, Mode=OneWay}" Margin="122.48,11.26,9,0" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="{DynamicResource MediumFontSize}" FontFamily="{DynamicResource AppFont}" Template="{DynamicResource TxtBoxTemplate}" Height="25" >

why is this different ?


The Binding statement will not look for the event you have defined. You must implement INotifyPropertyChanged instead.


I'm not quite certain what you're trying to accomplish. My understanding is that you are trying to bind the visibility of your label to a Property named LoadingControlVisibility that is defined in another class. If that is the case, then your path is wrong in the binding. Your binding should be as follows: Visibility="{Binding LoadingControlVisibility}"

0

精彩评论

暂无评论...
验证码 换一张
取 消