Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3979488
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:10:35+00:00 2026-05-20T05:10:35+00:00

I have the following definition of a LibraryStack: <s:LibraryStack Name=TaggingContainer Margin=20 Grid.Row=1 Grid.ColumnSpan=2 AllowDrop=True

  • 0

I have the following definition of a LibraryStack:

<s:LibraryStack Name="TaggingContainer" Margin="20" Grid.Row="1" Grid.ColumnSpan="2" AllowDrop="True" Height="300" Width="300" s:SurfaceDragDrop.DragLeave="TaggingContainer_DragLeave" s:SurfaceDragDrop.DragEnter="TaggingContainer_DragEnter" s:SurfaceDragDrop.PreviewDrop="LibraryStack_PreviewDrop">
            <s:LibraryStack.ItemTemplate>
                <DataTemplate>
                    <Label Content="{Binding Name}" Tag="{Binding}" FontSize="20" Margin="10,10,10,10" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" Background="#c49b14" BorderBrush="White" BorderThickness="2" s:Contacts.PreviewContactDown="Label_PreviewContactDown"></Label>
                </DataTemplate>
            </s:LibraryStack.ItemTemplate>
        </s:LibraryStack>

Now in the code-behind I want to iterate over all the labels that are contained in the LibraryStack (the label defined in the data template).

But if I use

foreach (FrameworkElement element in TaggingContainer.Items) {
}

I iterate over the data objects that are in the TaggingContainer and not the Datatemplates. How can I change that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:10:36+00:00Added an answer on May 20, 2026 at 5:10 am

    The easiest way is probably to find every LibraryStackItem or Label under the LibraryStack in the Visual Tree. Try this

    private void SomeMethod()
    {
        // Get All Labels
        List<Label> labels = GetVisualChildCollection<Label>(TaggingContainer);
        foreach (Label label in labels)
        {
            //...
        }
    }
    

    Alternatively you could get the container for each element and get the Label that way instead

    foreach (var element in TaggingContainer.Items)
    {
        LibraryStackItem libraryStackItem = TaggingContainer.ItemContainerGenerator.ContainerFromItem(element) as LibraryStackItem;
        Label label = VisualTreeHelpers.GetVisualChild<Label>(libraryStackItem);
    }
    

    GetVisualChild

    private static T GetVisualChild<T>(DependencyObject parent) where T : Visual
    {
        T child = default(T);
    
        int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
        for (int i = 0; i < numVisuals; i++)
        {
            Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
            child = v as T;
            if (child == null)
            {
                child = GetVisualChild<T>(v);
            }
            if (child != null)
            {
                break;
            }
        }
        return child;
    }
    

    GetVisualChildCollection

    public static List<T> GetVisualChildCollection<T>(object parent) where T : Visual
    {
        List<T> visualCollection = new List<T>();
        GetVisualChildCollection(parent as DependencyObject, visualCollection);
        return visualCollection;
    }
    private static void GetVisualChildCollection<T>(DependencyObject parent, List<T> visualCollection) where T : Visual
    {
        int count = VisualTreeHelper.GetChildrenCount(parent);
        for (int i = 0; i < count; i++)
        {
            DependencyObject child = VisualTreeHelper.GetChild(parent, i);
            if (child is T)
            {
                visualCollection.Add(child as T);
            }
            else if (child != null)
            {
                GetVisualChildCollection(child, visualCollection);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have run across an XML Schema with the following definition: <xs:simpleType name=ClassRankType> <xs:restriction
I have following definition in ivy.xml <dependency org=southbeach name=ego rev=4.3.1 conf=properties->asterik > <artifact name=ego
Suppose have following beach definition: <bean id=singletonBean class=...> <property name=instanceBean ref=instanceBean/> </bean> <bean id=instanceBean
I have the following definition... <bean id=fsi class=org.springframework.security.intercept.web.FilterSecurityInterceptor> <property name=authenticationManager ref=authenticationManager/> <property name=accessDecisionManager ref=httpRequestAccessDecisionManager/>
Let's have the following class definition: CThread::CThread () { this->hThread = NULL; this->hThreadId =
I have following enum definition public enum UploaderType { BrandLogo = 0, ReportingLogo =
I have the following definition. far int* near IntegerPointer; Does this mean, a pointer
I have the following definition at the top of my .ASCX file: <%@ Control
I have the following definition for an id field in an entity that is
Suppose I have the following table definition: CREATE TABLE x (i serial primary key,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.