Use dependency property UWP



  • I can't find a good example of using Dependency property. Now I've registered properties in the helpers class.

    private static readonly DependencyProperty FilterApplyProperty= DependencyProperty.Register("FilterApply", 
            typeof(ICommand),typeof(EffectListSelection),new PropertyMetadata(1,OnValuePropertyChanged));
    

    Here's the designer.

    public iCommand FilterValue
        {
            get { return (iCommand) GetValue(FilterApplyProperty); }
            set { SetValue(FilterApplyProperty, value);}
        }
    

    The method itself.

     private void OnClick(object sender, RoutedEventArgs e)
        {
    
        string listviewName = AssociatedObject.Name;
        temp = (e as ItemClickEventArgs).ClickedItem as FiltersViewModel;
        MainViewModel.Effect = temp.Type;
    
        this.EffectApply.Execute(this.temp.Type);  <---
    }
    

    Got it. I just had to call the team, and it worked.



  • For starters, DependencyProperty needed to work. Bindinganimation, style and stuff. Usually, it's necessary for the caste UI elements.

    Working with them is simple, just as usual. Plus, you can make a difference in style again, for example.


    My crystal ball says you're trying from a static method. OnValuePropertyChanged refer to the character or method of the copy. It certainly won't work. But you've got a copy of it as a parameter. dSo maybe you want

    EffectListSelection self = (EffectListSelection)d;
    self.Command();
    

    If you're actually not writing UI-object, maybe it makes sense not to use it. DependencyPropertyand ordinary properties, INotifyPropertyChanged


    By the way, you have DependencyProperty Not defined. You didn't give the whole code, but even in that piece you brought, the name of the properties you're registering."FilterApply"Does not match the real name of the properties (FilterValue) Wait for the bagos and the unworking chips. (CELL PLAYING) DependencyProperty Right.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2