开发者

trying to consume a WCF service in silverlight application?

开发者 https://www.devze.com 2023-04-11 17:40 出处:网络
I created a silver light project,where i am trying to load a datagrid in my main page.As I came to know that ADO.net is not supported in silverlight ,i made use of silver light enabled WCF service.I f

I created a silver light project,where i am trying to load a datagrid in my main page.As I came to know that ADO.net is not supported in silverlight ,i made use of silver light enabled WCF service.I followed the example here http://www.dotnetcurry.com/ShowArticle.aspx?ID=228

I am able to get the data from the database into the service but unable to display in my page and it doesn't throw any exception.Does it have some thing to do with the binding configurations or some thing.Because i am able to access the WCF service from the browser .so i think i am unable to load into the datagrid of my page.Here is my code

XAML:

 <Grid x:Name="LayoutRoot">
  开发者_开发技巧  <sdk:DataGrid x:Name="DetailsGrid" AutoGenerateColumns="False" Height="430" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="576" />
</Grid>

C#:

    DataServiceClient client = new DataServiceClient();
  client.ResourcesListCompleted  +=new EventHandler<ResourcesListCompletedEventArgs>(client_ResourcesListCompleted);
        client.ResourcesListAsync();
        InitializeComponent();

    void client_ResourcesListCompleted(object sender, ResourcesListCompletedEventArgs e)
    {

        DetailsGrid.ItemSource = e.Result;

    }


You've set AutoGenerateColumns="False" but then (assuming you haven't left it out of the code) not specified which columns you do want to display.

In the first instance set AutoGenerateColumns="True" to make sure you are getting data. This will display all the data for each record in the data set. If you don't want all the data set it to False and then specify which columns you do want to use. So assuming you have a field called FirstName in your data you'd have:

<sdk:DataGrid x:Name="dg" AutoGenerateColumns="False">
    <sdk:DataGrid.Columns>
        <sdk:DataGridTextColumn Header="First Name" 
                Binding="{Binding FirstName}" />
    </sdk:DataGrid.Columns>
    ....
</sdk:DataGrid>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号