Click here to Skip to main content
15,917,928 members
Home / Discussions / WPF
   

WPF

 
QuestionBinding WPF element to property of a class Pin
Prasoon Chaudhary23-Mar-10 20:33
Prasoon Chaudhary23-Mar-10 20:33 
I wish to bind 'Canvas.Left' of an ellipse to a property (iEllipse) of Class instance(bClass). This property gets updated from several locations. Following is the C# code:

namespace BindingTest
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public class BindingClass
    {
        public int iEllipseLeft { get; set; }
        public BindingClass()
        {
            iEllipseLeft = 30;
        }
    }

    public partial class Window1 : Window
    {

        //Declare at top, so we could use it from anywhere       
        BindingClass bClass;
            
        public Window1()
        {
            InitializeComponent();
            bClass = new BindingClass();
        }

        // Update property of class
        private void updateLoc()
        {
            Random random = new Random();
            bClass.iEllipseLeft = random.Next(0, 100);
        }
    }
}


And, this is the ellipse I want to bind. Basically I want to move this ellipse whenever bClass.iEllipseLeft gets changed.

<Canvas Margin="16,128,244,52" Background="#FFE8E8E8">
	<Ellipse Fill="#FFFE0C0C" Width="32" Height="32" Canvas.Left= "5" Canvas.Top="48"/>
</Canvas>


Whether it is possible by writing '{Binding=..}' in .XAML or by coding in .cs file, please let me know. I'll be happy in either way. It might be a very simple question, but I've just started using WPF and C#, so please help Smile | :)
AnswerRe: Binding WPF element to property of a class Pin
koleraba23-Mar-10 22:22
koleraba23-Mar-10 22:22 
AnswerRe: Binding WPF element to property of a class Pin
Prasoon Chaudhary24-Mar-10 23:40
Prasoon Chaudhary24-Mar-10 23:40 
QuestionCarousel website.. Beginner Pin
Yraith23-Mar-10 7:45
Yraith23-Mar-10 7:45 
AnswerRe: Carousel website.. Beginner Pin
Kunal Chowdhury «IN»23-Mar-10 16:57
professionalKunal Chowdhury «IN»23-Mar-10 16:57 
AnswerRe: Carousel website.. Beginner Pin
Abhinav S23-Mar-10 18:54
Abhinav S23-Mar-10 18:54 
GeneralRe: Carousel website.. Beginner Pin
Yraith24-Mar-10 5:02
Yraith24-Mar-10 5:02 
QuestionAdding additional Brushes to the Style of a ContentControl Pin
Alan Beasley22-Mar-10 3:06
Alan Beasley22-Mar-10 3:06 
AnswerRe: Adding additional Brushes to the Style of a ContentControl Pin
Abhinav S22-Mar-10 4:18
Abhinav S22-Mar-10 4:18 
GeneralRe: Adding additional Brushes to the Style of a ContentControl [modified] Pin
Alan Beasley22-Mar-10 5:25
Alan Beasley22-Mar-10 5:25 
GeneralRe: Adding additional Brushes to the Style of a ContentControl Pin
Abhinav S22-Mar-10 7:38
Abhinav S22-Mar-10 7:38 
GeneralRe: Adding additional Brushes to the Style of a ContentControl Pin
Alan Beasley22-Mar-10 8:06
Alan Beasley22-Mar-10 8:06 
GeneralRe: Adding additional Brushes to the Style of a ContentControl Pin
Katka Vaughan20-Apr-10 10:15
Katka Vaughan20-Apr-10 10:15 
GeneralRe: Adding additional Brushes to the Style of a ContentControl Pin
Alan Beasley20-Apr-10 22:34
Alan Beasley20-Apr-10 22:34 
GeneralRe: Adding additional Brushes to the Style of a ContentControl Pin
Katka Vaughan21-Apr-10 1:15
Katka Vaughan21-Apr-10 1:15 
GeneralRe: Adding additional Brushes to the Style of a ContentControl Pin
Alan Beasley21-Apr-10 1:29
Alan Beasley21-Apr-10 1:29 
QuestionObject reference not set to an instance of an object Pin
FEMDEV22-Mar-10 2:25
FEMDEV22-Mar-10 2:25 
AnswerRe: Object reference not set to an instance of an object Pin
Pete O'Hanlon22-Mar-10 2:32
mvePete O'Hanlon22-Mar-10 2:32 
GeneralRe: Object reference not set to an instance of an object Pin
FEMDEV22-Mar-10 3:30
FEMDEV22-Mar-10 3:30 
GeneralRe: Object reference not set to an instance of an object Pin
Kevin McFarlane22-Mar-10 7:02
Kevin McFarlane22-Mar-10 7:02 
QuestionCustom Binding Extension -- how to access source object.? Pin
quetzilla21-Mar-10 15:35
quetzilla21-Mar-10 15:35 
AnswerRe: Custom Binding Extension -- how to access source object.? Pin
quetzilla25-Mar-10 7:05
quetzilla25-Mar-10 7:05 
QuestionCustomizing Foreground (the moving part) of a progressbar in WPF Pin
2hdass21-Mar-10 8:11
2hdass21-Mar-10 8:11 
AnswerRe: Customizing Foreground (the moving part) of a progressbar in WPF Pin
Super Lloyd22-Mar-10 12:33
Super Lloyd22-Mar-10 12:33 
GeneralRe: Customizing Foreground (the moving part) of a progressbar in WPF Pin
2hdass24-Mar-10 19:04
2hdass24-Mar-10 19:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.