如何将生成的网格添加到另一个生成的子项?

时间:2017-03-27 14:37:57

标签: c# wpf xaml

我想制作一个用户列表。因此程序必须将DataBase中的所有用户加载到程序中。

我的设计已完成,我有一个XAML代码。现在我想将此XAML代码添加到-- function to work around bug in st_clip (fails when polygon barely intersects with raster) -- not sure how much damage this has on performance create or replace function st_clip_fuzzy( rast raster, nband integer[], geom geometry, nodataval double precision[] DEFAULT NULL, crop boolean DEFAULT TRUE ) returns raster as $$ declare rec record; g geometry; begin return st_clip($1, $2, $3, $4, $5); exception when others then select st_intersection(st_envelope(rast), geom) into g; raise warning 'st_clip_fuzzy: intersection %', st_astext(g); raise warning 'st_clip_fuzzy: area intersection %', st_area(g); raise warning 'st_clip_fuzzy: area pixel %', abs(ST_ScaleX(rast) * ST_ScaleY(rast)); raise warning 'st_clip_fuzzy: area ratio %', st_area(g) / abs(ST_ScaleX(rast) * ST_ScaleY(rast)); return ST_MakeEmptyRaster(0, 0, ST_UpperLeftX(rast), ST_UpperLeftY(rast), ST_ScaleX(rast), ST_ScaleY(rast), ST_SkewX(rast), ST_SkewY(rast), ST_SRID(rast)); end; $$ language 'plpgsql' immutable; CREATE OR REPLACE FUNCTION st_clip_fuzzy( rast raster, nband integer, geom geometry, nodataval double precision, crop boolean DEFAULT TRUE ) -- four more interfaces with different set of arguments 中。所以我必须添加所有Childrens等programmaticaly。

XAML代码是:

while Reader.Read()

我在XAML中使用MaterialDesign。 所以我必须将所有这些Childrens添加到Code-Behind(我在没有MVVM的情况下工作,因为整个程序都是代码隐藏所以我不想重新编写整个程序)。

我的代码到现在为止:

<materialDesign:Card Margin="4 4 0 0"  Padding="0" Width="250">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Margin="16 16 16 4" Style="{StaticResource MaterialDesignHeadlineTextBlock}">User 1</TextBlock>
                    <Separator Grid.Row="1" Style="{StaticResource MaterialDesignLightSeparator}"/>
                    <TextBlock Grid.Row="2" Margin="16 0 16 8" VerticalAlignment="Center" HorizontalAlignment="Left" Style="{StaticResource MaterialDesignBody2TextBlock}">Boss</TextBlock>
                    <StackPanel Grid.Row="2" Orientation="Horizontal" Margin="16 0 16 8" HorizontalAlignment="Right">
                        <Button HorizontalAlignment="Right" Style="{StaticResource MaterialDesignToolForegroundButton}" Width="30" Padding="2 0 2 0" materialDesign:RippleAssist.IsCentered="True">
                            <materialDesign:PackIcon Kind="Pencil" />
                        </Button>
                        <Button HorizontalAlignment="Right" Style="{StaticResource MaterialDesignToolForegroundButton}" Width="30" Padding="2 0 2 0" materialDesign:RippleAssist.IsCentered="True">
                            <materialDesign:PackIcon Kind="Delete" />
                        </Button>
                        <materialDesign:PopupBox HorizontalAlignment="Right" Padding="2 0 2 0">
                            <StackPanel>
                                <Button Content="More"/>
                                <Button Content="Rights"/>
                            </StackPanel>
                        </materialDesign:PopupBox>

                    </StackPanel>
                </Grid>
            </materialDesign:Card>

不,我必须将网格添加到卡中。但我无法用这种方式编码:

while(reader.Read())
                {
                    #region MaterialDesignCard
                    MaterialDesignThemes.Wpf.Card card = new MaterialDesignThemes.Wpf.Card();
                    card.Margin = new Thickness(4, 4, 0, 0);
                    card.Padding = new Thickness(0);
                    card.Width = 250;
                    #endregion
                    #region Grid
                    Grid grid = new Grid();

                    #endregion


                    wrapPanelEmployees.Children.Add(card);
                }

我怎样才能将生成的网格添加到另一个生成的孩子(卡片)?

1 个答案:

答案 0 :(得分:1)

我猜您可以将Content的{​​{1}}属性转换为Card,然后将该元素添加到其Grid集合中:

Children

编辑:如果您实际以编程方式创建Grid元素,则应将Card控件的Content属性设置为Grid:

Grid grid = card.Content as Grid;
if(grid != null)
    grid.Children.Add(grid);