?
Solved

Finding UserControl in Window  WPF

Posted on 2014-01-10
3
Medium Priority
?
581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 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 63

Expert Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 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