0

is it possible to set a Datasource through a reference?

public partial class GraphView : UserControl
{
    public ObservableCollection<ChartCollection<long>> signals { get; set; }

    public GraphView()
    {
       UCGraph.DataSource = this.signals;
    }
 }

and if I set the signals property should it update the Datasource?

MyGraphUC.signals = mySignals;

It doesn't seem to be working for me. Why?

1 Answer 1

1

No you can't directly because the variables UCDataGraph.DataSource and signals are not connected by any means. They just happen to point to the same instance after you assign them in your constructor (actually they will both point to null which is not an instance at all). That being said, you can leverage the setter to do your bidding like so:

public partial class GraphView : UserControl
{
    private ObservableCollection<ChartCollection<long>> _signals 
    public ObservableCollection<ChartCollection<long>> signals 
    { 
        get
        {
            return _signals;
        }

        set
        {
            this._signals = value;
            UCGraph.DataSource = this._signals;
        }

    }

    public GraphView()
    {
       UCGraph.DataSource = this.signals;
    }
 }

Alternatively you can just .Clear() the observable collection and refill it with the elements instead of changeing the collection itself if that is an feasible scenario for you.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, thats waht I needed! Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.