Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF Binding works only once

$
0
0

I've created a Binding with converter, but it updates target only once - when it is setted.
I've try to change modes, access modifiers, etc

When I call setMode("somestring") target didn't update

But it'll update once - when SetBinding is called.

Hope, sb helps me.

Best regards.

Here's the code:

public class Controller
    {
        private VisualController visual;
        //
        //constructors, etc...
        //
        public void setMode(string s)
        {
            ColorMap_C cmap = Visual.ColorMap;
            cmap.Nowmode = s;
            Visual.ColorMap = cmap;
        }
    }

public class ColorMap_C:DependencyObject
    {
        public static readonly DependencyProperty Nowmode_prop =
            DependencyProperty.Register(
                "Nowmode", typeof(string),
                typeof(ColorMap_C), new PropertyMetadata("normal"));
        public string Nowmode
        {
            get
            {
                return (string)GetValue(Nowmode_prop);
            }
            set
            {
                if (!ModesDescriptions_S.Instance.Descriptions.ContainsKey(value))
                    return;
                SetValue(Nowmode_prop, value);
            }
        }
        public class GradientToBrushConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {                
                ColorMap_C colorMap = value as ColorMap_C;
                Vessel3DTreeNode node = parameter as Vessel3DTreeNode;
                //....res calculating here...
                return new SolidColorBrush(res);
            }
            //convertBack not implemented
        }
        //Other: constructors, fields, etc...
    }
public class VisualController : DependencyObject, INotifyPropertyChanged
    {
        public static readonly DependencyProperty ColorMap_prop =
            DependencyProperty.Register("ColorMap", typeof(ColorMap_C),
                typeof(VisualController), null);

        public ColorMap_C ColorMap
        {
            get { return (ColorMap_C)GetValue(ColorMap_prop); }
            set
            {
                SetValue(ColorMap_prop, value);
                OnPropertyChanged("ColorMap");
            }
        }
        private NodeVisualFactory visualFactory;
        public VisualController()
        {
            visualFactory = new NodeVisualFactory(this);
        }
        //.........
    }

public class NodeVisualFactory : DependencyObject
    {
        private VisualController parent;
        public VisualController Parent
        {
            get { return parent; }
            set { parent = value; }
        }
        public NodeVisualFactory(VisualController parent)
        {
            this.parent = parent;
        }
        public ModelVisual3D getLeftTube(Vessel3DTreeNode node)
        {
            TubeVisual3D left = new TubeVisual3D();
            Binding b = new Binding();
            b.Source = Parent;
            b.ConverterParameter = node.LeftChild;
            b.Converter =new ColorMap_C.GradientToBrushConverter();
            b.Path = new PropertyPath("ColorMap");
            BindingOperations.SetBinding(left, TubeVisual3D.FillProperty, b);
        }
        //..........
    }



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>