The getter for Window.TitleBar (Window.cs:397-400) returns a new instance each time it is called:
public virtual TitleBar TitleBar { get { return factory.GetTitleBar(this); } }
This means that the following code in Window.set_DisplayState (Window.cs:336-338):
if (AlreadyInAskedState(value) || TitleBar == null) return; TitleBar.SetDisplayState(value);
uses two different instances of TitleBar, including a possible null reference (from PrimaryUIItemFactory.GetTitleBar).
Because Window.get_TitleBar returns a new instance on each call, both references to Window.TitleBar in Window.set_DisplayState should use the same local variable.
It may also be worth hiding the property TitleBar behind a method that declares the return of each call as a new, possibly null, object.
The getter for Window.TitleBar (Window.cs:397-400) returns a new instance each time it is called:
public virtual TitleBar TitleBar { get { return factory.GetTitleBar(this); } }
This means that the following code in Window.set_DisplayState (Window.cs:336-338):
if (AlreadyInAskedState(value) || TitleBar == null) return; TitleBar.SetDisplayState(value);
uses two different instances ofTitleBar
, including a possible null reference (fromPrimaryUIItemFactory.GetTitleBar
).Because
Window.get_TitleBar
returns a new instance on each call, both references toWindow.TitleBar
inWindow.set_DisplayState
should use the same local variable. It may also be worth hiding the propertyTitleBar
behind a method that declares the return of each call as a new, possibly null, object.