ProgressBar not updating on change to Maximum through binding

后端 未结 2 1196
甜味超标
甜味超标 2021-01-21 05:36


        
2条回答
  •  不知归路
    2021-01-21 06:24

    I was having trouble getting the solution here to work, but I found another work around. My progress bar wouldn't update as I changed the datasource of my object (11 of 11 would change to 10 of 10 and freeze the progress bar), and realized that I didn't need to update maximum value at all.

    Instead I used a converter on the value to convert it to a percent, and set my maximum at 100. The result displays the same, but without the bug for changing maximum value.

    public class CreatureStaminaConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var creature = (CreatureBase.CreatureEntityData) value;
            double max = creature.entityData.MaxStat;
            return creature.CurrentStamina/max*100;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
    
     
    

提交回复
热议问题