开发者

Silverlight templated Control databinding to custom properties

Is there some trick that I'm missing here?

I've created a templated control, very simple. One single property on it, and I'd like to databind from the (viewmodel/datacontext of the) page in which it's hosted to a custom property on the control. The property will eventually be a vector type object, defining the position of the control, however in an attempt to get this to work I've tried r开发者_StackOverflow社区educing it to a basic string property.

Each time I'm faced with "Set property 'SimpleGame.Classes.Sprite.Property' threw an exception.".

I can't even catch the exception in a debug session, the set property code is not being executed.

Do I need to use a dependency / attached property or something? I wouldn't have thought so...


Can you give us some code sample. Usualy when you try to bind a property it must be a dependency property or a property that use INotifyPropertyChanged Interface implements like ths

private string m_prop;
        public string Prop
        {
         get { return m_prop; }
         set { 
              m_prop = value; 
              NotifyPropertyChanged("Prop") 
          }
        }

    private void NotifyPropertyChanged(string propertyName)
    {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜