在WPF(MVVM)中的telerik GridView(或其他listview)中的ListView

时间:2015-11-28 13:03:54

标签: c# wpf listview binding radgridview

我在GridView中添加了一个ListView

  <tel:RadGridView AutoGenerateColumns="False" x:Name="ModuleGrid" ItemsSource="{Binding ProjectList,Source={StaticResource TowersVM},Mode=TwoWay}"
                             HorizontalAlignment="Stretch" ShowGroupPanel="False" ColumnWidth="*" ShowColumnHeaders="False" RowIndicatorVisibility="Collapsed" Height="500">
                <tel:StyleManager.Theme>
                    <tel:Windows8TouchTheme/>
                </tel:StyleManager.Theme>
                <tel:RadGridView.Columns>
                    <tel:GridViewImageColumn Width="150" x:Name="Img"  IsFilterable="False" DataMemberBinding="{Binding TowerImage}"/>
                    <!--<tel:GridViewDataColumn Width="100" x:Name="Img" Header="" IsFilterable="False" DataMemberBinding="{Binding TowerImage}"/>-->
                    <tel:GridViewColumn>
                        <tel:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <ListView x:Name="TemplateList" ItemsSource="{Binding UnitTypesList,Source={StaticResource TowersVM},Mode=TwoWay}">
                                    <ListView.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Horizontal"></StackPanel>
                                        </ItemsPanelTemplate>
                                    </ListView.ItemsPanel>

                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal" Margin="40,20,40,20">                                            
                                                <Grid x:Name="TemplateGrid">
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="Auto"/>
                                                        <RowDefinition Height="Auto"/>
                                                        <RowDefinition Height="Auto"/>
                                                        <RowDefinition Height="Auto"/>
                                                    </Grid.RowDefinitions>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto"/>
                                                        <ColumnDefinition Width="Auto"/>
                                                    </Grid.ColumnDefinitions>
                                                    <StackPanel Grid.Row="0" Orientation="Vertical" Margin="5,0,0,0">
                                                        <TextBlock FontSize="14" Text="{Binding Tower_Name}" FontWeight="ExtraBold"/>
                                                        <TextBlock FontSize="9" Text="{Binding Location}"/>
                                                    </StackPanel>
                                                    <TextBlock Grid.Row="1" Text="{Binding Unit_type_desc}" Margin="5,5,0,0"/>
                                                    <StackPanel Grid.Row="2" Grid.Column="0" Orientation="Horizontal" Margin="5,5,0,0">
                                                        <Image Source="/Resources/rupee_icon.png" Width="30"/>
                                                        <StackPanel Orientation="Vertical" Margin="5,0,0,0">
                                                            <TextBlock Text="Price"/>
                                                            <TextBlock Text="{Binding List_price}">
                                              <Run Text=" Cr."/>
                                                            </TextBlock>
                                                        </StackPanel>
                                                    </StackPanel>
                                                    <StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" Margin="20,5,0,0">
                                                        <Image Source="/Resources/area_icon.png" Width="30"/>
                                                        <StackPanel Orientation="Vertical" Margin="5,0,0,0">
                                                            <TextBlock Text="Area"/>
                                                            <TextBlock Text="{Binding Carpet_area}">
                                                                <Run Text=" Sqft."/>
                                                            </TextBlock>
                                                        </StackPanel>
                                                    </StackPanel>
                                                    <Button BorderBrush="LightGreen" Background="White" Grid.Row="3" Grid.Column="0" Margin="0,5,0,5">
                                                        <StackPanel Orientation="Horizontal">
                                                            <TextBlock Text="Available : "/>
                                                            <TextBlock Text="{Binding Available,Source={StaticResource TowersVM},Mode=TwoWay}"/>
                                                        </StackPanel>
                                                    </Button>
                                                    <Button BorderBrush="Red" Background="White" Grid.Row="3" Grid.Column="1" Margin="20,5,0,5">
                                                        <StackPanel Orientation="Horizontal">
                                                            <TextBlock Text="Sold : "/>
                                                            <TextBlock Text="{Binding Sold,Source={StaticResource TowersVM},Mode=TwoWay}"/>
                                                        </StackPanel>
                                                    </Button>

                                                </Grid>                                              
                                            </StackPanel>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                            </DataTemplate>
                        </tel:GridViewColumn.CellTemplate>
                    </tel:GridViewColumn>
                </tel:RadGridView.Columns>
            </tel:RadGridView>

我想要的是: 一个GridView行,其中一个Item将包含一个ListView(具有不同数量的Items)。 问题:所有RadGrid行在ListView中具有相同数量的项目。

ViewModel代码:

 public async void PopulateProjects()
       {           
           var vAllProjList = await _projectsRepo.GetAllAsync();
           foreach(var proj in vAllProjList)
           {
               //UnitTypesList.Clear();
               ProjectList.Add(new ProjectTowerUnitTypeModel() { Projectid = proj.Id, ProjectName = proj.Name });
               var vProjSpecificUnitList = await _unitTypesRepo.FindAsync(q => q.Class_id == proj.Id);


               foreach(var unit in vProjSpecificUnitList)
               {
                   UnitTypesList.Add(new ProjectTowerUnitTypeModel() { });
               }
           }
       }

1 个答案:

答案 0 :(得分:-1)

我通过将子项的ItemsSource Collection作为Parent的Model属性来实现它。