Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Dependency Property PropertyChangedCallback exception

$
0
0
 

 public bool HasConnection
 {
 get { return (bool)GetValue(HasConnectionProperty); }
    set { SetValue(HasConnectionProperty, value); }
}

public static readonly DependencyProperty HasConnectionProperty =
 DependencyProperty.Register(
  "HasConnection",
        typeof(bool),
        typeof(NetworkNode),
        new FrameworkPropertyMetadata(
            false,
            FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
            new PropertyChangedCallback(HasConnectionChangedCallBack)));


private static void HasConnectionChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
 NetworkNode nn = (NetworkNode)d;
 Ellipse el = nn.GetTemplateChild("PART_inner") as Ellipse;
    if (el.PART_inner.Visibility == ...) <-- exception el is null
            //..code..
}

This code works fine, except if I change the HasConnection property in visual studio properties panel, or in xaml I set HasConnection = "True", and I run the program throws an excetion: Object reference not set to an instance of an object.

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>