-1

I have View and its ViewModel. In View, I have some Panels that has binding to some properties in my ViewModel;

For example first property is SomeObject. In that panel I have some textboxes, that has binding to some properties in SomeObject class. All bindings in ViewModel and classes implements INPC.

That textbox, in panel, has binding to its property in SomeObject class this way: SomeObject.Property.

In that view I have a Save button. I need change the IsEnabled property of my button every time when something was entered in textboxes or changed in panel.

I've done it only for SomeObject property in my viewmodel by changing IsEnabled property bound to button from SomeObject's setter. But when I change something in properties of my SomeObject it doesn't call the setter of main SomeObject in ViewModel, and I can't change my IsEnabled property from SomeObject class.

<controls:ExpandableSettingsPanel Header="REFUND" IsExpanded="{Binding RefundCustomerConfigurationEnabled, Mode=TwoWay}" ..>
    <StackPanel..>
        <CheckBox Content="Allowed within reversal period" IsChecked="{Binding RefundCustomerConfiguration.IsAllowedWithinReversalPeriod, Mode=TwoWay}"/>
        <TextBlock Style="{DynamicResource GrayTextBlockStyle}" Text="Minimal amount to be refunded"/>
        <WrapPanel>
            <TextBlock Text="€" .. />
            <controls:MementoTextBox Text="{Binding RefundCustomerConfiguration.MinimalAmountToBeRefunded, Mode=TwoWay, 
                NotifyOnValidationError=True, StringFormat=\{0:N2\}, 
                TargetNullValue='', 
                UpdateSourceTrigger=PropertyChanged, 
                ValidatesOnNotifyDataErrors=True, 
                ValidatesOnExceptions=True}"  ..>
                    <i:Interaction.Behaviors>
                        <behaviors:TextBoxInputRegExBehavior 
                            EmptyValue="0.00"
                            IgnoreSpace="True"
                            RegularExpression="^\d{1,2}(\.?\d{1,2})?$" 
                            MaxLength="6"
                            />
                    </i:Interaction.Behaviors>
            </controls:MementoTextBox>
        </WrapPanel>
        <TextBlock Style="{DynamicResource GrayTextBlockStyle}" Text="Minimal bank statement line age" ../>
        <controls:MementoTextBox Text="{Binding RefundCustomerConfiguration.MinimalBankStatementLineAge, 
            Mode=TwoWay,
            NotifyOnValidationError=True,
            ValidatesOnNotifyDataErrors=True,
            UpdateSourceTrigger=PropertyChanged,
            ValidatesOnExceptions=True }" ..>
            <i:Interaction.Behaviors>
                <behaviors:TextBoxInputRegExBehavior 
                        EmptyValue="0"
                        IgnoreSpace="True"
                        RegularExpression="^\d{1,3}$" 
                        MaxLength="3"
                        />
            </i:Interaction.Behaviors>
        </controls:MementoTextBox>
    </StackPanel>
</controls:ExpandableSettingsPanel>

This is my XAML part.

public RefundCustomerConfiguration RefundCustomerConfiguration
{
    get { return _refundCustomerConfiguration; }
    set
    {
        SetProperty(ref _refundCustomerConfiguration, value);
        OnPropertyChanged("RefundCustomerConfigurationEnabled");
    }
}

[Required(ErrorMessage = "This field is required")]
public bool IsAllowedWithinReversalPeriod
{
    get { return GetValue(() => IsAllowedWithinReversalPeriod); }
    set
    {
        SetPropertyValue(value);
    }
}

And this is my properties; First - in ViewModel. Second - in first property class.

Rachel
  • 130,264
  • 66
  • 304
  • 490
Alex Wyler
  • 59
  • 1
  • 1
  • 8
  • 3
    This looks like a puzzle :) You should share a part of code – Mehmet Mar 17 '16 at 13:31
  • Provide us your code, so we can find the error – FKutsche Mar 17 '16 at 13:31
  • 2
    It sounds like what you need to learn to use is the `ICommand` interface, http://www.codeproject.com/Articles/238657/How-to-use-Commands-in-WPF. – CodingGorilla Mar 17 '16 at 13:34
  • 1
    Can you include the XAML for your Save button? It should bind to a `SaveCommand` in the ViewModel, and the `ICommand` interface provides you with a `CanExecute` check which is automatically used to enable/disable the button bound to the command. There's an example [here](http://stackoverflow.com/a/3531935/302677) if you want it. – Rachel Mar 17 '16 at 14:01

1 Answers1

0

Just bind button's visibility property to the Visibility method in the class which realize INotifyPropertyChanged interface as like this:

public Visibility btnVisible
{
   get
   {
      if(<your condition>)
         return Visibility.Visible;
      else
         return Visibility.Collapsed;
   }
}
SYL
  • 337
  • 4
  • 16