Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Items collection must be empty before using ItemsSource.

Items collection must be empty before using ItemsSource.

Scheduled Pinned Locked Moved WPF
helpwpfcsharpwcf
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jhoga
    wrote on last edited by
    #1

    I keep getting this error. I kind of new to wpf and not sure what the issue is. Here is my code:

    <DataGrid AutoGenerateColumns="False" Height="770" Name="DataGrid1" Width="1506" ItemsSource="{Binding}">
    <Style TargetType="{x:Type DataGridRow}" >
    <Style.Triggers>
    <DataTrigger Binding="{Binding Alert_Level}" Value="1">
    <Setter Property="Background" Value="LightYellow" />
    </DataTrigger>
    </Style.Triggers>
    </Style>

    <DataGrid.Columns>

    <DataGridTextColumn Header="ID" Binding="{Binding TicketID}" IsReadOnly="True" Width="70" FontSize="24" />
    <DataGridTextColumn Header="Date" Binding="{Binding Date_Entered}" IsReadOnly="True" Width="100" FontSize="24" />
    <DataGridTextColumn Header="Input By" Binding="{Binding Requestor}" IsReadOnly="True" Width="200" FontSize="24"/>
    <DataGridTextColumn Header="Telephone" Binding="{Binding Requestor_telep}" IsReadOnly="True" Width="120" FontSize="24"/>
    <DataGridTextColumn Header="Status" Binding="{Binding Status}" IsReadOnly="True" Width="120" FontSize="24"/>
    <DataGridTextColumn Header="Alert" Binding="{Binding Alert_Level}" IsReadOnly="True" Width="40" FontSize="24"/>
    <DataGridTextColumn Header="Assigned" Binding="{Binding Assigned_To}" IsReadOnly="True" Width="200" FontSize="24"/>
    <DataGridTextColumn Header="Issue" Binding="{Binding Problem_detail}" IsReadOnly="True" Width="300*" FontSize="24"/>
    </DataGrid.Columns>

    </DataGrid>

    Thanks

    M 1 Reply Last reply
    0
    • J jhoga

      I keep getting this error. I kind of new to wpf and not sure what the issue is. Here is my code:

      <DataGrid AutoGenerateColumns="False" Height="770" Name="DataGrid1" Width="1506" ItemsSource="{Binding}">
      <Style TargetType="{x:Type DataGridRow}" >
      <Style.Triggers>
      <DataTrigger Binding="{Binding Alert_Level}" Value="1">
      <Setter Property="Background" Value="LightYellow" />
      </DataTrigger>
      </Style.Triggers>
      </Style>

      <DataGrid.Columns>

      <DataGridTextColumn Header="ID" Binding="{Binding TicketID}" IsReadOnly="True" Width="70" FontSize="24" />
      <DataGridTextColumn Header="Date" Binding="{Binding Date_Entered}" IsReadOnly="True" Width="100" FontSize="24" />
      <DataGridTextColumn Header="Input By" Binding="{Binding Requestor}" IsReadOnly="True" Width="200" FontSize="24"/>
      <DataGridTextColumn Header="Telephone" Binding="{Binding Requestor_telep}" IsReadOnly="True" Width="120" FontSize="24"/>
      <DataGridTextColumn Header="Status" Binding="{Binding Status}" IsReadOnly="True" Width="120" FontSize="24"/>
      <DataGridTextColumn Header="Alert" Binding="{Binding Alert_Level}" IsReadOnly="True" Width="40" FontSize="24"/>
      <DataGridTextColumn Header="Assigned" Binding="{Binding Assigned_To}" IsReadOnly="True" Width="200" FontSize="24"/>
      <DataGridTextColumn Header="Issue" Binding="{Binding Problem_detail}" IsReadOnly="True" Width="300*" FontSize="24"/>
      </DataGrid.Columns>

      </DataGrid>

      Thanks

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      I would guess based on what you've shown, the Style ends up being just a datagrid item (an object representing a datagrid row). That style should be in the resources somewhere, for example

              <Style.Triggers>
                  <DataTrigger Binding="{Binding Alert\_Level}" Value="1">
                      <Setter Property="Background" Value="LightYellow" />
                  </DataTrigger>
              </Style.Triggers>
          
      
      ...
      

      Mark Salsbery :java:

      J 1 Reply Last reply
      0
      • M Mark Salsbery

        I would guess based on what you've shown, the Style ends up being just a datagrid item (an object representing a datagrid row). That style should be in the resources somewhere, for example

                <Style.Triggers>
                    <DataTrigger Binding="{Binding Alert\_Level}" Value="1">
                        <Setter Property="Background" Value="LightYellow" />
                    </DataTrigger>
                </Style.Triggers>
            
        
        ...
        

        Mark Salsbery :java:

        J Offline
        J Offline
        jhoga
        wrote on last edited by
        #3

        Thanks mark, That took care of my error. I still can not get the background to show a color base on a value. But that is a complete separate issue. Thanks for your help ;)

        M 1 Reply Last reply
        0
        • J jhoga

          Thanks mark, That took care of my error. I still can not get the background to show a color base on a value. But that is a complete separate issue. Thanks for your help ;)

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          jhoga wrote:

          I still can not get the background to show a color base on a value.

          Maybe the resource needs to be at least one level up the tree from the datagrid. Regardless, perhaps try using ItemContainerStyle instead, something like this

                  <Style.Triggers>
                      <DataTrigger Binding="{Binding Alert\_Level}" Value="1">
                          <Setter Property="Background" Value="LightYellow" />
                      </DataTrigger>
                  </Style.Triggers>
              
          
          ...
          

          Mark Salsbery :java:

          J 1 Reply Last reply
          0
          • M Mark Salsbery

            jhoga wrote:

            I still can not get the background to show a color base on a value.

            Maybe the resource needs to be at least one level up the tree from the datagrid. Regardless, perhaps try using ItemContainerStyle instead, something like this

                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Alert\_Level}" Value="1">
                            <Setter Property="Background" Value="LightYellow" />
                        </DataTrigger>
                    </Style.Triggers>
                
            
            ...
            

            Mark Salsbery :java:

            J Offline
            J Offline
            jhoga
            wrote on last edited by
            #5

            Thanks Mark, I tried that with no luck. I found the issue the value of Alert_Level was not numeric. Once I changed it to an int everything worked fine. Thanks for your help. :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups