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 8153991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:11:52+00:00 2026-06-06T16:11:52+00:00

I have problem with WPF – I’m quiet new in this smart technology. So

  • 0

I have problem with WPF – I’m quiet new in this smart technology. So the problem is:

I have a window. In this window’s resources I have stored an element – eg. a Grid with unique key (assume x:Key=”myGrid”). In this Grid I have a TextBox identified by a name (x:Name=”myTextBox”).
My Window contains only an empty Grid (named eg. winGrid). I programmatically set the myGrid as a child of the winGrid. And now, in runtime, I want to get a reference to the myTextBox object. I spent plenty of time googling, but nothing worked for me (FindName and similar methods).

Do you have please any idea, what I have to do to get the ball rolling?

Here is (pseudo)code snippet once more:

<Window x:Class="LoginForm.RidicWindow"
    ...>
<Window.Resources>
    <Grid x:Key="myGrid">
        <Border...
        <Grid...
            ...
            <TextBlock x:Name="myTextBlock" Grid.Column="0".../>
         </Grid>
    </Grid>
 </Window.Resources>
 <Grid x:Name="winGrid">
     ...
 </Grid>

And now I set the myGrid as a child of winGrid:
(something like)

winGrid.Childrens.Clear();
winGrid.Childrens.Add((Grid)FindResource(myGrid));

And now I want to get a reference to myTextBlock, which is descendant of the myGrid.

I tried something like

((Grid)FindResource(myGrid)).FindByName("myTextBlock");

this, of course, doesn’t work.

Hope you understand me, what I want to get.
Lot of thanks!

  • 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-06-06T16:11:54+00:00Added an answer on June 6, 2026 at 4:11 pm

    You can not do this (By the way, you can, but it’s really bad, ugly and not recommended) The resources of a window to serve another purpose.

    As mentioned, you must create a component (Usercontrol or other).. Although there are some other options for what you seek.
    You can try some of what I wrote below:


    1) Creating a custom component may be a UserControl, Grid or anything else…

        <Grid x:Class="Project.MyGridControl"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                     mc:Ignorable="d" 
                     d:DesignHeight="300" d:DesignWidth="300">
    <!-- Content -->
        </Grid>
    

    and

            MyGridControl control = new MyGridControl();
            winGrid.Childrens.Add(control);
    


    2) A little more complicated:

    <Grid  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <!-- Content -->
    </Grid>
    

    and

    Grid myCustomGrid = XamlReader.Load(uriResource) as Grid;
    winGrid.Childrens.Add(myCustomGrid);
    

    In this option you will not have like a grid control to instantiate. (I see it often used in reports). You should create a .xaml and define it as a resource.


    To find components you should look in the visual tree (as already responded)…

    ( How can I find WPF controls by name or type? )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small problem, when I open a new window in WPF like
I have a problem in wpf xaml and i'm pretty new on this so
i have a problem with wpf-grid in .net-framework. I have defined a grid in
I have a problem trying to develop a WPF page. I have a window
I'm very new to .Net and WPF and have a problem. The code is
I am new to WPF and xaml and I have a problem with my
I have this problem. I use caliburn micro in WPF. In view I have
I use caliburn micro and MEF in wpf and I have this problem. I
I have this problem that My WPF App in its MainWindow: public partial class
I using multilanguage solution from this thread Multilanguage in WPF But i have problem

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.