2010-08-06 49 views
0

我想列出datagrid(wpf)中的webservice的數據,但我不知道我做錯了什麼,或者給我錯誤或不列出任何東西。 這就是我現在的樣子。在DataGrid中列出來自webservice的數據WPF

WINDOWS.XAML

<Window x:Class="IssueAddinOutlook.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit" 
    Title="Issue List" Height="424" Width="696"> 

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="102*" /> 
     <ColumnDefinition Width="590*" /> 
    </Grid.ColumnDefinitions> 
    <Label Height="41" Margin="172,0,265,0" Name="label1" VerticalAlignment="Top" FontSize="22" Grid.Column="1">Issue List</Label> 

    <dg:DataGrid x:Name="dataGrid" AutoGenerateColumns="True" 
     AlternationCount="2" 

     HeadersVisibility="All" 
     HorizontalGridLinesBrush="#DDDDDD" 
     VerticalGridLinesBrush="#DDDDDD" Grid.ColumnSpan="2" Margin="0,0,28,26"> 

     <dg:DataGrid.Columns> 
      <dg:DataGridTextColumn Header="ID Issue" Binding="{Binding Path=Id}" /> 
      <dg:DataGridTextColumn Header="Order Id" Binding="{Binding Path=OrderId}" /> 
      <dg:DataGridTextColumn Header="Is Done" Binding="{Binding Path=IsDone}" /> 
      <dg:DataGridTextColumn Header="Final Comment" Binding="{Binding Path=FinalComment}" /> 
      <dg:DataGridTextColumn Header="Actual Hours" Binding="{Binding Path=ActualHours}" /> 
      <dg:DataGridTextColumn Header="Group Id" Binding="{Binding Path=GroupId}" /> 
     </dg:DataGrid.Columns> 
    </dg:DataGrid> 
</Grid> 
<Window.Resources> 
    <Style x:Key="columnHeaderStyle" TargetType="{x:Type dg:DataGridColumnHeader}"> 
     <Setter Property="Background"> 
      <Setter.Value> 
       <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> 
        <LinearGradientBrush.GradientStops> 
         <GradientStop Color="Navy" Offset="0" /> 
         <GradientStop Color="LightBlue" Offset="1" /> 
        </LinearGradientBrush.GradientStops> 
       </LinearGradientBrush> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="Foreground" Value="White" /> 
    </Style> 
    <Style x:Key="rowStyle" TargetType="dg:DataGridRow"> 
     <Setter Property="FontFamily" Value="Verdana" /> 
     <Setter Property="FontSize" Value="10" /> 
     <Style.Triggers> 
      <Trigger Property="AlternationIndex" Value="0"> 
       <Setter Property="Background" Value="White" /> 
      </Trigger> 
      <Trigger Property="AlternationIndex" Value="1"> 
       <Setter Property="Background" Value="#DDDDDD" /> 
      </Trigger> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Setter Property="Background" Value="#BBBBBB" /> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 
</Window.Resources> 

而且WINDOWS.XAML.CS

Issuereference.Tasks issueRef = new Issuereference.Tasks(); 
Issuereference.TASK[] tasksList = issueRef.GetTasks(39); 
dataGrid.ItemsSource = tasksList.ToList(); 

與此代碼提供在使用ItemsSource之前,錯誤Items集合必須是空的。 任何人都可以幫助我嗎?

回答

1

你的代碼似乎很好。無論如何,分配ItemsSource,有沒有出現在網格內的任何東西?還是有應用程序的任何部分手動將項目添加到DataGrid?該錯誤消息通常意味着應用程序的一部分已更新ItemsControl的集合,同時它具有分配的ItemsSource。希望這是有道理的。

+0

沒有數據的網格是空的。 – Luis 2010-08-06 21:49:55

+0

grrrrrrrrr它現在的工作:D ...我不知道我做了什麼:D – Luis 2010-08-06 21:52:52

+0

那麼,對你有好處。 ;) – ASanch 2010-08-06 22:13:00