Solved

WPF: Bind a propertie in a WPF user control

Posted on 2010-09-22
8
878 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

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

18 Experts available now in Live!

Get 1:1 Help Now