Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"value cannot be null. parameter name container" xaml

Tags:

c#

wpf

xaml

I am maintaining a legacy WPF application, and I'm new to WPF so be gentle :) On the window tag I have the following attribute:

WindowState="{Binding Source={x:Static gui:GlobalWindowState.Instance}, Path=Maximized, Converter={StaticResource WindowStateConverter}}"

When the XAML is open I am seeing the error:

"value cannot be null. parameter name container"

The code compiles and executes fine, and the error only shows when the Xaml is open. But seeing that error really bothers me.

Google wasn't much help. I'm guessing most people just ignore it.

public object Convert(object value, Type targetType, object parameter, CultureInfo culture){
like image 879
Jacob Brewer Avatar asked Oct 31 '22 23:10

Jacob Brewer


1 Answers

I would suggest, if you are using the MVVM design-pattern and you have a view-model available to this XAML code, to bind your WindowState to a property of your view-model, and write this property to output the value that it needs. There are ways to ascertain within your view-model property whether it is running during design-time (ie, being displayed within Visual Studio or Blend) or runtime. Thus you can easily control how your XAML is displayed both at runtime and in your designer (Visual Studio). Within your property, you would explicitly check for null values to clear this error. And, you can add logging statements to investigate the actual operation.

like image 137
James Hurst Avatar answered Nov 15 '22 06:11

James Hurst