StrataFrame Forum

Bind to image.imagelocation

http://forum.strataframe.net/Topic6556.aspx

By Chan - 2/2/2007

Hi,

Anyway to bind to image.imagelocation?

I tried to set imagelocation and text to bindingproperty, but doesn't work.



Any ideas?



Thank you
By StrataFrame Team - 2/6/2007

The problem is that the ImageLocation property does not have an ImageLocationChanged event.  You will need to subclass the PictureBox class and either add an event called ImageLocationChanged of type System.EventHandler or implement the INotifyPropertyChanged interface on the class and raise the PropertyChanged event when the ImageLocation changes.
By Chan - 5/19/2007

Hi,

I tried to the code below but I cant drop my picturebox on form. Any ideas?

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using MicroFour.StrataFrame.UI.Windows.Forms;
using JK.Framework.Base;

namespace JK.Framework.UI.Windows.Forms
{
    [Designer(typeof(System.Windows.Forms.Design.ControlDesigner))]
    public class ImageLocationPictureBox : System.Windows.Forms.PictureBox, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
       
        public string ImageLocation2
        {
            get
            {
                return this.ImageLocation;
            }
            set
            {
                string lcImageLocation = this.ImageLocation;
                if (this.CheckPropertyChanged<string>("ImageLocation2", ref lcImageLocation, ref value))
                {
                    this.ImageLocation = value;
                    this.ImageLocation2Changed();
                }
            }
        }
        protected bool CheckPropertyChanged<T>(string propertyName, ref T oldValue, ref T newValue)
        {
            if (oldValue == null && newValue == null)
            {
                return false;
            }
            if ((oldValue == null && newValue != null) || !oldValue.Equals((T)newValue))
            {
                oldValue = newValue;
                FirePropertyChanged(propertyName);
                return true;
            }
            return false;
        }
        protected void FirePropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        private void ImageLocation2Changed()
        {
            this.FirePropertyChanged("ImageLocation2");
        }
    }
}
By Chan - 5/20/2007

Hi,

I found my mistake BigGrin

By StrataFrame Team - 5/21/2007

I'm glad you got it working.  Many times, if you're getting exceptions from your property gets or sets at design-time because they contain code that only works at runtime, you can test the this.DesignMode property to determine whether the control is running or just in the designer.

Warning: that this.DesignMode property always returns false if you test it in the constructor of the control.  Once you're out of the constructor, it works fine, but as long as you're in the constructor, it hasn't been set, yet.