WPF Toolkit problem when apply with MVVM

May 15, 2009 at 4:23 AM

I have study on MVVM and walk though the sample that use ListView, I not found any problem then I try to apply MVVM with WPF Toolkit

After I have created Model and ViewModel, I have created CustomView like below

<Grid>
    <tk:DataGridRow>
        <tk:DataGridRow.Item>
            <tk:DataGridTextColumn Binding="{Binding Path=Name}" Header="Name" MaxWidth="50" MinWidth="50" />
        </tk:DataGridRow.Item>
    </tk:DataGridRow>
</Grid>


And I have updated MainView as:

<tk:DataGrid ItemsSource="{Binding Employees}">
    <tk:DataGrid.ItemTemplate>
        <DataTemplate>
            <views:EmployeeView />
        </DataTemplate>
    </tk:DataGrid.ItemTemplate>
</tk:DataGrid>


This is working but it has another additional columns add to DataGrid (Model has about 5 columns) then I have set AutoGenerateColumns="False" at the MainView and it display blank 4 rows but not have any column to display, even column header still not display. (I have load data for 4 rows that I think it loading correctly but not display)

What I'm missing? and how to solving this problem?

Thanks,
Ek

May 15, 2009 at 6:28 AM

Does views:EmployeeView actually describe how to display the items? If not, that's your problem.

Try taking out the ItemTemplate, set AutoGenerateColumns="False" and then define the columns manually in the DataGrid instance. If that works, something is likely wrong with your ItemTemplate and I'd be willing to bet that it has to do with EmployeeView in that case. (I haven't tried using the ItemTemplate with the DataGrid, but the XAML looks correct at a glance.)

May 15, 2009 at 6:44 AM

In my EmployeeView describe like this

<Grid>
    <tk:DataGridRow>
        <tk:DataGridRow.Item>
            <tk:DataGridTextColumn Binding="{Binding Path=Name}" Header="Name" MaxWidth="50" MinWidth="50" />
        </tk:DataGridRow.Item>
    </tk:DataGridRow>
</Grid>


So I have tried to create column in MainView like below, it working correctly so I think that the problem is in my EmployeeView but I don't know how what am I missing in this point?

<tk:DataGrid ItemsSource="{Binding Employees}" AutoGenerateColumns="False">
    <tk:DataGrid.Columns>
        <tk:DataGridTextColumn Binding="{Binding Path=Name}" />
    </tk:DataGrid.Columns>
</tk:DataGrid>