I'm doing some binding, and using a third party control.
The issue I have is (or so I've worked (and therefore think)) the control is not part of the visual tree. So, I can't bind direct to the DataContext in the normal manner. Instead, I have to do the following
<StackPanel.Resources>
<loc:BackupResultsViewModel x:Key="MyVm" />
<CollectionViewSource x:Key="StatusCollection" Source="{Binding Source={StaticResource MyVm}, Path=PassFailStatus}" />
</StackPanel.Resources>
<xctk:Chart Height="300" Width="300" ShowLegend="True" >
<xctk:Chart.Areas>
<xctk:Area.Series>
<xctk:Series Title="Overall status" DataPointsSource="{Binding Source={StaticResource StatusCollection}}">
<xctk:Series.Layout>
<xctk:PieLayout />
</xctk:Series.Layout>
<xctk:Series.DataPointBindings>
<xctk:BindingInfo PropertyName="Y">
<xctk:BindingInfo.Binding>
<Binding Path="Y"/>
</xctk:BindingInfo.Binding>
</xctk:BindingInfo>
<xctk:BindingInfo PropertyName="Label">
<xctk:BindingInfo.Binding>
<Binding Path="Label"/>
</xctk:BindingInfo.Binding>
</xctk:BindingInfo>
</xctk:Series.DataPointBindings>
</xctk:Series>
</xctk:Area.Series>
</xctk:Area>
</xctk:Chart.Areas>
</xctk:Chart>
</StackPanel>
So, the line of code
<xctk:Series Title="Overall status" DataPointsSource="{Binding Source={StaticResource StatusCollection}}">
Shows it's binding the source to a StaticResource, and this is defined under StackPanel.Resources
And it works when I set the data in the constructor of my ViewModel.
However, I won't know the data at that point, the user will have to make some selections first and then press a button at which point I need to pass the new data to my control.
The problem I have is it does not work! The graph still renders but, with no data.
This is my property I'm binding too
private ObservableCollection<DataPoint> _passFailStatus;
public ObservableCollection<DataPoint> PassFailStatus
{
get { return this._passFailStatus; }
set
{
if (this._passFailStatus == value)
return;
this._passFailStatus = value;
OnPropertyChanged("PassFailStatus");
}
}
And the control
private void ShowComplete(int backupComplete, int backupFailed, int backupSkipped)
{
//this.PassFailStatus initialized in constructor and in this method, same result
App.Current.Dispatcher.Invoke((Action) (() =>
{
try
{
this.PassFailStatus.Add(new DataPoint(-99, backupComplete, "Copied"));
this.PassFailStatus.Add(new DataPoint(-99, backupFailed, "Failed"));
this.PassFailStatus.Add(new DataPoint(-99, backupSkipped, "Skipped"));
}
catch (Exception ex)
{
string s = ex.ToString();//for debugging
}
}));
}
There are no exceptions thrown, and if I put a watch in my Property, I can see the setter is set, but afterwards, the getter is never called. I'm lost what I need to do.