How do I add items dynamically to a WrapPanel?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Falkeli
    New Member
    • Feb 2012
    • 19

    How do I add items dynamically to a WrapPanel?

    I have the following XAML:
    Code:
    <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">
                [I]other content[/I]
            </ToolBar>
            <WrapPanel Name="wrapPanel1" >
                [I]other content[/I]
                <Label Content="Label" Height="28" Name="label1" />
            </WrapPanel>
        </DockPanel>
    </Window>
    I want to add content to wrapPanel1 - I tried the following code:
    Code:
        if (info.Attributes == FileAttributes.Directory)
            wrapPanel1.Children.Add(new FolderEntry(info.Name));
        else
            wrapPanel1.Children.Add(new FileEntry(info.Name));
    for some reason, the items don't show up. How can I fix that problem?
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    The items need to be WPF controls.
    Does the FileEntry inherit from something like FrameworkElemen t?

    Comment

    Working...