views:

39

answers:

1

I am new to WPF so after reading for a while I deduce that my problem needs to be handled with this pattern: DependencyProperty.

I want my toggleButton to have another boolean property.

My problem is where should I assign this property, and how? Inside the object that is bound to the toggleButton?

Let's say I have a class cell (which is bound to this button) that when clicked I want that from this point on, it would hold new face with trigger on.

My new property will be:

 bool wasClick 

Can someone explain to me how I should write it and tell me more about this new concept.

EDIT: the main topic is where should i define it ' so i want it asoocited to a button but where shold i write the all lets say i have a class whos binded to a button shoul i write

public static readonly DependencyProperty IsSpinningProperty = DependencyProperty.Register( ... "IsSpinning", typeof(Boolean),

in this class or should i write it in my view model ?? so where ? and how ?

+1  A: 

As the name implies (kind of poorly), a dependency property is a property whose value can depend on something else. Generally, this means a property whose value gets determined automatically (and dynamically) by the WPF framework under certain conditions. The most common conditions are:

  • The property has a default value, or inherits its value from an ancestor in the visual tree. In this case, the property's value is determined without it ever being set.
  • The property is the target of data binding.
  • The property's value is set by an animation.

Not all properties whose value gets set by the WPF framework need to be dependency properties. Any CLR property with a public getter and setter can be the source of a two-way data binding.

In your case, it sounds like you don't really need a dependency property, not if you're using a view model. You could just do this (assuming that you've implemented property-change notification in your class):

private bool _IsChecked;

public bool IsChecked
{
   get { return _IsChecked; } }
   set
   {
      if (value == _IsChecked)
      {
         return;
      }
      _IsChecked = value;
      WasChecked = WasChecked || value;
      OnPropertyChanged("IsChecked");
   }
}

private bool _WasChecked;

public bool WasChecked
{
   get { return _WasChecked; }
   private set
   {
      if (value == _WasChecked)
      {
         return;
      }
      _WasChecked = value;
      OnPropertyChanged("WasChecked");
   }
}
Robert Rossney
so i could go in the xaml and do :<Trigger Property="IWasChecked" Value="True"> <Setter TargetName="star1" Property="Visibility" Value="Visible"/>????? <Setter TargetName="star2" Property="Visibility" Value="Collapsed"/> </Trigger>
yoav.str
@Robert i allready used it's defult proprty : http://stackoverflow.com/questions/3871467/memory-card-game-wpf-problemI need another proprty
yoav.str
I don't understand what you're saying.
Robert Rossney
not metter i succeeded using IsEnable thank you .
yoav.str