shawn
Topic Author
Posts: 13
Joined: 14 Mar 2019, 10:05

DataBinding of CustomControl didn't work in Unity3d

08 Apr 2019, 13:33

I writed a custom control with some DependencyProperty.
    public class UIImage : Panel{
        public static readonly DependencyProperty SourceProperty =DependencyProperty.Register("Source", typeof(Uri), typeof(UIImage), new FrameworkPropertyMetadata(PropertyChangedCallback));
        public Uri Source {
            get { return GetValue(SourceProperty) as Uri; }
            set { SetValue(SourceProperty, value); }
        } 
    }
I created a databing when i used this control.
<nc:UIImage x:Name="BindImg" Height="166" Canvas.Left="1086" Canvas.Top="175" Width="156" Source="{Binding MyURI, Mode=OneWay}"/>
    public class VMMMMMMM : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private Uri uri;
        public Uri MyURI
        {
            get { return uri; }
            set { uri = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MyURI")); }
        }
    }
It works fine on vs blend,but didn't work in Unity3d. but I am able to bind some data to system controll such as Image,Label successfully. I have no idea if there is any woring operation!
 
User avatar
sfernandez
Site Admin
Posts: 3264
Joined: 22 Dec 2011, 19:20

Re: DataBinding of CustomControl didn't work in Unity3d

08 Apr 2019, 14:18

I was able to reproduce the problem, there is a bug in our code when getting the value from a VieModel's Uri property.
Could you please report it in our bugtracker?

In the meantime as a workaround you can define the ViewModel's property as a string, then the binding will work fine.
 
shawn
Topic Author
Posts: 13
Joined: 14 Mar 2019, 10:05

Re: DataBinding of CustomControl didn't work in Unity3d

08 Apr 2019, 14:53

I was able to reproduce the problem, there is a bug in our code when getting the value from a VieModel's Uri property.
Could you please report it in our bugtracker?

In the meantime as a workaround you can define the ViewModel's property as a string, then the binding will work fine.
ok! I did it. If use ViewModel's property as a string to insted ,and it works fine

Who is online

Users browsing this forum: No registered users and 3 guests