How to Bind the Visibility of a Label to the Size of a List

1

I have a list of objects of type "BasicVariable", a% of them%, and I need the Graphic Interface to show a Label when the number of items in this collection exceeds 1000, I think the binding is correct but I did not get one how the counter and UI are updated every addition / removal of an object of this class ...

Here is the label I need to update:

<Label x:Name="configFilePath_Copy" Content="BasicVariable can't exceed 1000" HorizontalAlignment="Right" Margin="0,0,11,62" VerticalAlignment="Bottom" RenderTransformOrigin="0.5,0.5" Width="154" Foreground="Red">
  <Label.Style>
    <Style TargetType="{x:Type Label}">
      <Setter Property="Visibility" Value="Collapsed"/>
      <Style.Triggers>
        <DataTrigger Binding="{Binding BVExceed}" Value="True">
          <Setter Property="Visibility" Value="Visible"/>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </Label.Style>
</Label>

Here I collapsed a Boolean property that returns whether or not it has more than 1000 objects

public bool BVExceed
{
  get { return NumberOfBasicVariablesExceeded(); }
  set
  {
    if(value != NumberOfBasicVariablesExceeded())
    {
      NumberOfBasicVariablesExceeded();
      RaisePropertyChanged("BVExceeded");
    }
  }
}

Here the method that interacts with the other viewmodel that has ObservableCollection

public bool NumberOfBasicVariablesExceeded()
{
  if (BasicVariableViewModel != null)
  { return (BasicVariableViewModel.BasicVariables.Count >= 1000); }
  else
    return false; 
}

As I'm new to the MVVM and WPF standard, I know that my implementation is wrong in both code and XAML, I would like to understand exactly how to do this binding of datatriggers in order to implement correctly

    
asked by anonymous 31.07.2018 / 18:38

1 answer

1

Dude, the question I see is that your BVExceed variable is not changed. Try to put the NumberOfBasicVariablesExceeded() method together with the add or remove of your collection and the return of it you assign in the variable BVExceed .

In case your BVExceed would look something like this:

private bool _bvExceed;
public bool BVExceed
{
  get { return _bvExceed; }
  set
  {
      _bvExceed = value;
      RaisePropertyChanged("BVExceed");
  }
}

and within your add / remove method you call NumberOfBasicVariablesExceeded()

BVExceed = NumberOfBasicVariablesExceeded();
    
31.07.2018 / 19:10