1
I have a list of objects of type "Basicvariable", a ObservableCollection
of them, and I need the Graphical Interface to display a Label when the number of items in this Collection exceeds 1000, I think Binding is correct but I couldn’t find a way to update the counter and UI to each addition/removal of an object in this class...
Here’s 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 have placed 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 possesses the observablecollection
public bool NumberOfBasicVariablesExceeded()
{
if (BasicVariableViewModel != null)
{ return (BasicVariableViewModel.BasicVariables.Count >= 1000); }
else
return false;
}
As I am new to the MVVM standard and WPF, I know my implementation is wrong in both the code and XAML, I would like to understand exactly what is the standard of doing this data triggers Binding to be able to implement correctly
I understood, but now I saw that there is a method that can use Oncollectionchanged, using a Notifycollectionchangedeventargs... Wouldn’t it be more correct to use it? I’m feeling that what I’m doing on the show is actually kind of funny
– Arthuro Verissimo