Items collection must be empty before using ItemsSource.
-
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
-
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
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:
-
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:
-
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 ;)
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:
-
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: