Solved

Finding UserControl in Window  WPF

Posted on 2014-01-10
3
533 Views
Last Modified: 2014-01-10
I have a window that has a wrap panel.  In that wrap panel I have placed some viewboxes.  In each of the viewboxes I have placed a simple usercontrol.  How do I assign properties to my usercontrols?  I just can't figure out how to drill down and get to my usercontrol properties.  Sorry I have no code to give as a starting point as I am clueless.  Here is my xaml for the page, if that helps:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WPF_Custom_Control="clr-namespace:WPF_Custom_Control;assembly=WPF_Custom_Control" x:Class="Window1"
    Title="Window1" Height="1080" Width="1920">
    <Grid>
        <WrapPanel HorizontalAlignment="Left" Height="934" Margin="10,10,0,0" VerticalAlignment="Top" Width="1892">
            <Viewbox Height="100" Width="100" Stretch="Uniform" StretchDirection="Both" Name="vb1">
                <WPF_Custom_Control:UserControl1/>
            </Viewbox>
            <Viewbox Height="100" Width="100" Stretch="Uniform" StretchDirection="Both" Name="vb2">
                <WPF_Custom_Control:UserControl1/>
            </Viewbox>
            <Viewbox Height="100" Width="100" Stretch="Uniform" StretchDirection="Both" Name="vb3">
                <WPF_Custom_Control:UserControl1/>
            </Viewbox>
            <Viewbox Height="100" Width="100" Stretch="Uniform" StretchDirection="Both" Name="vb4">
                <WPF_Custom_Control:UserControl1/>
            </Viewbox>
            <Viewbox Height="100" Width="100" Stretch="Uniform" StretchDirection="Both" Name="vb5">
                <WPF_Custom_Control:UserControl1/>
            </Viewbox>
            <Viewbox Height="100" Width="100" Stretch="Uniform" StretchDirection="Both" Name="vb6">
                <WPF_Custom_Control:UserControl1/>
            </Viewbox>
            <Viewbox Height="100" Width="100" Stretch="Uniform" StretchDirection="Both" Name="vb7">
                <WPF_Custom_Control:UserControl1/>
            </Viewbox>
            <Viewbox Height="100" Width="100" Stretch="Uniform" StretchDirection="Both" Name="vb8">
                <WPF_Custom_Control:UserControl1/>
            </Viewbox>
            <Viewbox Height="100" Width="100" Stretch="Uniform" StretchDirection="Both" Name="vb9">
                <WPF_Custom_Control:UserControl1/>
            </Viewbox>
            <Viewbox Height="100" Width="100" Stretch="Uniform" StretchDirection="Both" Name="vb10">
                <WPF_Custom_Control:UserControl1/>
            </Viewbox>
        </WrapPanel>
        <Button Content="Button" HorizontalAlignment="Left" Margin="116,1003,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>

    </Grid>
</Window>

Open in new window


Thank you for any help on this.
0
Comment
Question by:G Scott
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39771280
First thing you need to do is give the x.Name property of the controls you need to use to find them your user control, the WrapPanel and the UserControl. So your WrapPannel should be something like this, do the same to all the user controls :
<WrapPanel x:Name="MyWrapPanel" HorizontalAlignment="Left" Height="934" Margin="10,10,0,0" VerticalAlignment="Top" Width="1892">

Open in new window

then when you wish to find one of your user control to change ones of its property do the following
 
Dim b As WPF_Custom_Control:UserControl1 = CType(MyWrapPanel.FindName("uc9"), WPF_Custom_Control:UserControl1)
b.ThePropertyToChange = "Value to set it to"

Open in new window

0
 
LVL 1

Author Closing Comment

by:G Scott
ID: 39771485
I was thinking this was way more complex.  Thank you so much.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39771489
Not a problem, glad to help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now