小编use*_*785的帖子

如何将项目动态添加到 WrapPanel?

我有以下 XAML:

<Window x:Class="ImageComparing.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="350" Width="525" xmlns:my="clr-namespace:ImageComparing" Title="Image comparing">
    <DockPanel>
        <ToolBar Name="toolbar1" DockPanel.Dock="Top" Height="41" Background="#FFA5D95A">
            /*other content*/
        </ToolBar>
        <WrapPanel Name="wrapPanel1" >
            /*other content*/
            <Label Content="Label" Height="28" Name="label1" />
        </WrapPanel>
    </DockPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)

我想添加内容wrapPanel1- 我尝试了以下代码:

if (info.Attributes == FileAttributes.Directory)
    wrapPanel1.Children.Add(new FolderEntry(info.Name));
else
    wrapPanel1.Children.Add(new FileEntry(info.Name));
Run Code Online (Sandbox Code Playgroud)

出于某种原因,这些项目没有出现。我该如何解决这个问题?

c# wpf

4
推荐指数
1
解决办法
5553
查看次数

标签 统计

c# ×1

wpf ×1