Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, maybe everybody can help me with Dependency Properties and a custom Control, this costum Control contians a grid, the grid shall be createsd progammatically- new columns with Buttons and external controls.
I have a dependency properties in this custom Control, but when i call the custom Control then the grid doesn't Change.

It seems the problem is that the grid is in another task? because nothing will created in the Grid, no column, no button. Waht do I wrong?

What I have tried:

my dependency property :
public static DependencyProperty Symbol1Name =
          DependencyProperty.Register("Sym1Name", typeof(string), typeof(UserControl1), new FrameworkPropertyMetadata("test", OnSymbol1PropertyChanged))


public string Sym1Name
       {
           get { return (string)this.GetValue(UserControl1.Symbol1Name); }
           set { this.SetValue(UserControl1.Symbol1Name, value); }
       }

The onChange Function
private static void OnSymbol1PropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
       {
           UserControl1 ak = dependencyObject as UserControl1;
           ak.OnPropertyChanged("Symbol1Name");
           ak.OnSymbol1PropertyChanged(e);

}

the function to Change. the Change function works in normal WPF App
:
private void OnSymbol1PropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            try
            {
                

                
                change(Sym1Name, 0);
                

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Posted
Updated 3-Apr-18 3:36am

Not sure what your issue is since you do not have enough for me to tell you. However, you have a DependencyProperty, and for some reason have also implemented INotifyPropertyChanged. That should not be required. Should be able to do everything without the DependencyProperty and just implement INotifyPropertyChanged. That may make your problem easier to deal with since no longer have to deal with statics when you handle the change.
 
Share this answer
 
Thanks I had a couple of problems with the logic of DependencyProperties. I found a short but good tutorial in web. After that I made a couple of changes and now it works:

public static readonly DependencyProperty Symbol1Name =
         DependencyProperty.Register("Sym1Name", typeof(string), typeof(UserControl1), new FrameworkPropertyMetadata(new string('t',10), OnSymbol1PropertyChanged));


public string Sym1Name
        {
            get { return (string) this.GetValue(Symbol1Name); }
            set { this.SetValue(Symbol1Name, value); }
        }


private static void OnSymbol1PropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            UserControl1 ak = dependencyObject as UserControl1;            
            ak.InitName(e,0);
        }

This following functions creates a new Column with a couple of elements.
public void InitName(DependencyPropertyChangedEventArgs e, int column)
       {
           string test = e.NewValue.ToString();


           ColumnDefinition c1 = new ColumnDefinition();
           newColumnDefinition(c1, test);
           newBoarder(column);
           newGraphic(column, test);
           CreateDynamicExpander(column);
           if (!istGerade(column)) Grid1.ColumnDefinitions[column].Width = new GridLength(0);
           Grid1.HorizontalAlignment = HorizontalAlignment.Stretch;
           Grid1.VerticalAlignment = VerticalAlignment.Top;

       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900