?
Solved

WPF: Bind a propertie in a WPF user control

Posted on 2010-09-22
8
Medium Priority
?
886 Views
Last Modified: 2012-05-10
HI!

I'm new to WPF so I need some help.

I'm working on a usercontrol.

I have this code.

   xmlns:apng="clr-namespace:Apng;assembly=ApngImage"
    Title="Window1" Height="200" Width="200" Background="Red" >
    <Grid>
        <Border Margin="10,10,10,10">
            <apng:ApngImage Name="apngControl1" Stretch="Fill" Path="chompy2.png" Fps="25" />
        </Border>
    </Grid>

But the image that I have hard coding here "chompy2.png" I like to set from a propertie instead.

How do I  do that?
0
Comment
Question by:AWestEng
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 8

Accepted Solution

by:
Gururaj Badam earned 800 total points
ID: 33732356


0
 
LVL 10

Assisted Solution

by:joriszwaenepoel
joriszwaenepoel earned 800 total points
ID: 33732437
Together with the Binding (see answer from Novice Novice), you also need to set the "DataContext".

For example:

this.DataContext = theObject;
0
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33732448
@joriszwaenep… - You're right.

I'd assumed that would have been done as the code snippet is not complete
0
Technology Partners: 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!

 
LVL 1

Author Comment

by:AWestEng
ID: 33732478
what is this
this.DataContext = theObject;
and where should I put it?
0
 
LVL 1

Author Comment

by:AWestEng
ID: 33732480

<UserControl x:Class="HostingWpfUserControlInWf.ucAPng"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:apng="clr-namespace:Apng;assembly=ApngImage"
Height="144" Width="172" Background="AliceBlue">
<Grid>
<apng:ApngImage Name="apngControl1" Stretch="Fill" Path="{Binding Path=Image}" Fps="25" />
</Grid>
</UserControl>
0
 
LVL 10

Assisted Solution

by:joriszwaenepoel
joriszwaenepoel earned 800 total points
ID: 33732494
theObject => this is the object with a property called "Image" that you want to use for your databinding

You should put that line of code somewhere in your code, where you have created or selected the object that you want to bind to.  It could be the "Loaded" event, or it could be a property setter in case of a usercontrol ...  
0
 
LVL 8

Assisted Solution

by:Gururaj Badam
Gururaj Badam earned 800 total points
ID: 33732587
Original code

 

Modified

 
0
 
LVL 6

Assisted Solution

by:rajeshjamnadas
rajeshjamnadas earned 400 total points
ID: 33743249
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 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