Question

I am beginnerof silverlight application using c# and xaml. What i am trying to do is to display information like:

SerialNumber  FirstName LastName //These are headings and below is the data
s0             ss1       ss1L
s1             ss2       ss2L 

where s0 ss1 ss1L and s1 ss2 ss2L must be List.

What My problem is :

It just show the headings but not data below like this: http://prntscr.com/3axadr But show nothing below the headings.

My code is below :

My Project Name is DEV_CENTER and MainPage.Xaml is

<UserControl x:Class="DEV_CENTER.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:vm="clr-namespace:DEV_CENTER"
             xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <UserControl.Resources>
        <vm:ProgramViewModel x:Key="ProgramViewModel"/>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White">
        <data:DataGrid Grid.Row="0" x:Name="gridPrograms" AutoGenerateColumns="False" ItemsSource="{Binding Path=Ssss1 }" IsReadOnly="True"  DataContext="{StaticResource ProgramViewModel}" >
            <data:DataGrid.Columns>
                <data:DataGridTextColumn Header="SerialNumber" Binding="{Binding Path=sss1}" Width="2*"></data:DataGridTextColumn>
                <data:DataGridTextColumn Header="FirstName" Binding="{Binding Path=sss2}" Width="2*"></data:DataGridTextColumn>
                <data:DataGridTextColumn Header="LastName" Binding="{Binding Path=sss3}" Width="3*"></data:DataGridTextColumn>
            </data:DataGrid.Columns>
        </data:DataGrid>
    </Grid>
</UserControl>

You can use all code to test. Could some one please tell me why it don't show " s0 ss1 ss1L" and s1 ss2 ss2L ? Is there anything wrong in Mvvm logic ? or anything else ?

Était-ce utile?

La solution

Your bindings are all wrong - you're binding to weird property names. Is this actually the case in your code or did it get messed up when you were writing the question?

Anyway, your grid should look like this:

<data:DataGrid Grid.Row="0" x:Name="gridPrograms" AutoGenerateColumns="False" ItemsSource="{Binding Path=Programs}" IsReadOnly="True"  DataContext="{StaticResource ProgramViewModel}" >
    <data:DataGrid.Columns>
        <data:DataGridTextColumn Header="SerialNumber" Binding="{Binding Path=SerialNumber}" Width="2*"></data:DataGridTextColumn>
        <data:DataGridTextColumn Header="FirstName" Binding="{Binding Path=FirstName}" Width="2*"></data:DataGridTextColumn>
        <data:DataGridTextColumn Header="LastName" Binding="{Binding Path=LastName}" Width="3*"></data:DataGridTextColumn>
    </data:DataGrid.Columns>
</data:DataGrid>

Also, it's always good to have a look at Visual Studio's output window when debugging - it may contain helpful binding error messages which will allow you to understand why your xaml doesn't behave as expected.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top