0

I have a simple Ellispis on a wpf that I bind to an Array item "Data[0]" to animate it. Issue is that when I bind it to that array, and its value toggle "true/false" there is no impact on the UI.

But when I change the binding to another public bool from the same class. No problem

<Ellipse Width="19"
Height="18"
Margin="29,137,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Fill="{Binding Data[0], 
    Converter={StaticResource BooleanToBrushConverter}, 
    Mode=OneWay,
    UpdateSourceTrigger=PropertyChanged}"
Stroke="Black" />

When I bind to that Array, no update on the UI:

    public bool[] Data
    {
        get{ return _data; }
        set{ _data= value; }
    }
    private bool[] _data= new Boolean[20];

When I do the binding to that bool, it is working:

    public bool DataSimple
    {
        get { return _dataSimple; }
        set { _dataSimple=value; }
    }
    private bool _dataSimple;

This is used to refresh the values and control that it reached and both are showing good result in Debug:

    private void RefreshData(object sender, EventArgs e)
    {
        _data= _process.DataRes;
        _dataSimple= _process.DataRes[0];
        Debug.WriteLine(_data[0]);
        Debug.WriteLine(_dataSimple);
    }

Can someone try help me on this ? thanks

2
  • It looks to me like it's because you're binding to the bool array index 0, not to the bool array itself (which has the getter/setter). Try creating a BooleanArrayToBrushConverter, where you take just the first element and return its Brush. Then, change your binding to `Fill="{BInding Data, Converter={StaticResource BooleanArrayToBrushConverter},". I'm also confused as to how any of this is working without an INotifyPropertyChanged, but I digress. Commented Dec 10, 2020 at 17:32
  • By toggle i meant "value = not value" switch from "true to false" or "false to true". I am real new on C#. But with all your comment I did it. Instead of using array i used ObservableCollection i binded it to a custome class and also added INotifyPropertyChanged then it worked. I need to read more about it cause it work but it is not clear in my mind how all behave and interact. Thanks guys Commented Dec 11, 2020 at 6:13

1 Answer 1

1

Your question is not clear as to exactly what you're changing and expecting to trigger an update to the user interface.

If you're updating individual bool values, then replace bool[] with ObservableCollection<bool> and initialise it with the appropriate number of items.

If you're supplying a whole new array of bool values then your classes need to implement INotifyPropertyChanged for the updated properties.

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

Comments

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.