Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WPF: Bind a propertie in a WPF user control

Posted on 2010-09-22
8
Medium Priority
?
889 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 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