views:

58

answers:

1

Does anyone have any idea why my ListBox would not populate when running in non Visual Studio Debug version? When running in debug version(F5) it perfectly fine without any breakpoints, but when I run in non debug(Ctrl+F5) it doesn't get populated.

I don't even know where to start regarding this as google shows nothing useful and I cant use the debugger as it works fine while debugging.

public partial class ErrorLog: Window
    {
        /// <summary>
        /// Collection of all errors
        /// </summary>
        public static SafeObservable<ErrorMessage> ErrorList
        {
            get {
                return ErrorLog.errorList; 
            }
            set
            {
                ErrorLog.errorList = value;
            }
        } private static SafeObservable<ErrorMessage> errorList = new SafeObservable<ErrorMessage>();

        /// <summary>
        /// Default constrcutor
        /// </summary>
        public ErrorLog()
        {
            InitializeComponent();
        }

        private void Clear_Click(object sender, RoutedEventArgs e)
        {
            //ErrorLog.ErrorList.Clear();
        }
    }

A SafeObservable class is just an extension to the normal ObservableColleciton class making use of the dispatcher to invoke if necessary to update UI from a different thread. I use this collection throughout my project in about 12 different places and it works perfectly fine. But in this single instance it doesn't.

Link to SafeObservable is here

The XAML code is below

<Window x:Class="Dashboard.ErrorLog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Dashboard"
    Title="ErrorLog" Height="448" Width="822" WindowStyle="ToolWindow">
    <Grid Background="#222222">
        <ListBox Name="Error_listBox" ItemsSource="{Binding Source={x:Static local:ErrorLog.ErrorList}}" Margin="12,12,12,41" IsSynchronizedWithCurrentItem="True" />
        <Button Height="23" HorizontalAlignment="Left" Margin="12,0,0,12" Name="Clear" VerticalAlignment="Bottom" Width="75" Click="Clear_Click">Clear</Button>
    </Grid>
</Window>

Any help is highly appreciated.

A: 

Thats really strange.

It is working if I simply call any function from the main window.

I added ErrorLog.ErrorList.Clear() just after the main window is initialised, ant it is working fine now. Anyone have any ideas to why this is like that? Is it something to do with the collection being static?

I don't like having random code such as that just to make something work... There must be a nicer way to do it.

Thanks for the suggestion Austin

LnDCobra