iam trying to hide and show LiveCharts series with checkboxes, but its not working :( This is my inspiration from :How can I hide and show LiveCharts series with dynamically created chart, and dynamic checkboxes? I have something a little bit different, i didnt use foreach loop , because i dont know how to do with that ( if someone knows how he did it please let me know ) , please help iam lost
ViewModel:
public void BasicLineExample()
{
var count = 2;
var val1 = new List<string>() { line1 };//(line=times (example: 00:01:45.215,00:01:45.215)
var val2 = new List<string>() { line2 };
for (int i = 1; i <= count; i++)
{
var lineSeries = new LineSeries
{
Title = "MachineResultTrue"
};
if (i == 1)
{
lineSeries.Values = new ChartValues<string>(val1);
}
else if (i == 2)
{
lineSeries.Values = new ChartValues<string>(val2);
}
SeriesCollection.Add(lineSeries);
}
}
private Series _LineSerie;
public Series LineSerie
{
get { return _LineSerie; }
set
{
if (value != _LineSerie)
{
_LineSerie = value;
NotifyPropertyChanged();
}
}
}
private bool _Visibility;
public bool Visibility
{
get { return _Visibility; }
set
{
if (value != _Visibility)
{
_Visibility = value;
if (LineSerie != null)
{
if (value == true)
{
LineSerie.Visibility = System.Windows.Visibility.Visible;
}
else
{
LineSerie.Visibility = System.Windows.Visibility.Collapsed;
}
}
NotifyPropertyChanged();
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
My XAML:
<ItemsControl
ItemsSource="{Binding SeriesCollection,Mode=TwoWay}"DataContext="{Binding Main1, Source={StaticResource Locator}}"
Grid.IsSharedSizeScope="True" Grid.Row="1" Grid.Column="1"
Margin="2,24,10,10" Grid.RowSpan="2">
<ItemsControl.ItemTemplate >
<DataTemplate
DataType="{}">
<Border
x:Name="Border"
Padding="8">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition
SharedSizeGroup="Checkerz" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<CheckBox Margin="10,0,5,0"
VerticalAlignment="Center" Content="{Binding LineSeries.Title}"
IsChecked="{Binding Visibility}" RenderTransformOrigin="0.919,1.287" />
<StackPanel
Margin="8 0 0 0"
Grid.Column="1">
</StackPanel>
</Grid>
</Border>
<DataTemplate.Triggers>
<DataTrigger
Binding="{Binding IsSelected}"
Value="True">
<Setter
TargetName="Border"
Property="Background"
Value="{DynamicResource MaterialDesignSelection}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Aucun commentaire:
Enregistrer un commentaire