Solved

WPF: Bind a propertie in a WPF user control

Posted on 2010-09-22
8
879 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 8

Accepted Solution

by:
Gururaj Badam earned 200 total points
ID: 33732356


0
 
LVL 10

Assisted Solution

by:joriszwaenepoel
joriszwaenepoel earned 200 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
 
LVL 1

Author Comment

by:AWestEng
ID: 33732478
what is this
this.DataContext = theObject;
and where should I put it?
0
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.

 
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 200 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 200 total points
ID: 33732587
Original code

 

Modified

 
0
 
LVL 6

Assisted Solution

by:rajeshjamnadas
rajeshjamnadas earned 100 total points
ID: 33743249
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

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

22 Experts available now in Live!

Get 1:1 Help Now