Click here to Skip to main content
15,886,199 members

Unhandled Error in Silverlight Application (Code: 4004)

soniaTan asked:

Open original thread
Error:
An UnHandled exception('Unhandled Error in Silverlight Application (Code: 4004)
Category: ManagedRuntimeError
Message: System.Windows.Markup.XamlParseException: [Line: 0 Position:0]---> System.ArgumentNullExecption: Value Cannot be Null.)

XAML:-
XML
<ComboBox Width="100" SelectedItem="SUPPLIER" ItemsSource="{Binding}" Height="22"  HorizontalAlignment="Center" Margin="0,0,2,0"  Name="cmbsup" VerticalAlignment="Bottom"  >
                       <ComboBox.ItemTemplate>
                           <DataTemplate>
                               <StackPanel Orientation="Horizontal">
                                   <CheckBox IsChecked="{Binding IsSelected,Mode=TwoWay}" Content="{Binding Name}" x:Name="chk" Click="chk_Click"></CheckBox>
                               </StackPanel>
                           </DataTemplate>
                       </ComboBox.ItemTemplate>
                   </ComboBox>

XML
<ComboBox Width="100" Height="22"  HorizontalAlignment="Center" Margin="0,0,2,0" Name="cmbyr" VerticalAlignment="Bottom" >
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <CheckBox IsChecked="{Binding IsYear,Mode=TwoWay}" Content="{Binding Year}" x:Name="chk1" Click="chk1_Click"></CheckBox>
                                </StackPanel>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>

CODE:-
C#
void t2_GetPurComboCompleted(object sender, DaService.GetPurComboCompletedEventArgs e)
        {

            PagedCollectionView p = new PagedCollectionView(e.Result);
            cmbprod.Items.Add("PRODUCT");
            foreach (string k in e.Result.AsEnumerable().Select(g => g.PROD_TYPE).Distinct())
            {
                cmbprod.Items.Add(k);
            }
            cmbprod.SelectedIndex = 0;

            foreach (string k in e.Result.AsEnumerable().Select(g => g.YEAR).Distinct())
            {
                dt.Add(new data { Year = k, IsYear = false });
            }
            cmbyr.ItemsSource = dt;
            cmbpmon.Items.Add("MONTH");
            foreach (string k in e.Result.AsEnumerable().Select(g => g.MONTH).Distinct())
            {
                cmbpmon.Items.Add(k);
            }
            cmbpmon.SelectedIndex = 0;
            cmbpotyp.Items.Add("POTYPE");
            foreach (int k in e.Result.AsEnumerable().Select(g => g.PO_TYP).Distinct())
            {
                cmbpotyp.Items.Add(k);
            }
            cmbpotyp.SelectedIndex = 0;
            cmbbuyer.Items.Add("BUYER");
            foreach (string k in e.Result.AsEnumerable().Select(g => g.Buyer).Distinct())
            {
                cmbbuyer.Items.Add(k);
            }
            cmbbuyer.SelectedIndex = 0;


            foreach (string k in e.Result.AsEnumerable().Select(g => g.Sup_Name).Distinct())
            {
                dt.Add(new data { Name=k,IsSelected=false});
            }

            cmbsup.ItemsSource = dt;
            cmbposubtyp.Items.Add("POSUBTYPE");

            ReadDataFromDatabase();
        }

     private void chk_Click(object sender, RoutedEventArgs e)
        {
            List<data> dt = (List<data>)cmbsup.ItemsSource;
            string ddd = "";
            foreach (data d in dt)
            {
                if ((bool)d.IsSelected)
                {
                    ddd += ",'" + d.Name + "'";
                }
            }
            if(ddd!="")
            ddd = ddd.Substring(1);
            supp = ddd;
            timer(); 
            ReadDataFromDatabase();
        }

        private void chk1_Click(object sender, RoutedEventArgs e)
        {
            List<data> dt1 = (List<data>)cmbyr.ItemsSource;
            string ddd = "";
            foreach (data d in dt1)
            {
                if ((bool)d.IsSelected)
                {
                    ddd += ",'" + d.Name + "'";
                }
            }
            if (ddd != "")
                ddd = ddd.Substring(1);
            supp = ddd;
            timer();
            ReadDataFromDatabase();
        }
public class data
    {
       private string Sup_name;
        private bool? isSelected;
        private string Yr_name;
        private bool? isyear;

        public data() { }

        public string Name
        {
            get { return Sup_name; }
            set
            {
                Sup_name = value;

                NotifyPropertyChanged(&quot;Name&quot;);
            }
        }

        public bool? IsSelected
        {
            get { return isSelected; }
            set
            {
                isSelected = value;
                NotifyPropertyChanged(&quot;IsSelected&quot;);
            }
        }
        public string Year
        {
            get { return Yr_name; }
            set
            {
                Yr_name = value;

                NotifyPropertyChanged(&quot;Year&quot;);
            }
        }

        public bool? IsYear
        {
            get { return isyear; }
            set
            {
                isyear = value;
                NotifyPropertyChanged(&quot;IsYear&quot;);
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
Tags: Silverlight

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900