简体   繁体   中英

C# wpf wont refresh using array binding

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM