Solved

Finding UserControl in Window  WPF

Posted on 2014-01-10
3
527 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

20 Experts available now in Live!

Get 1:1 Help Now