为什么超出最大值或最小值时不会更新进度条?

时间:2023-02-04 16:05:37
        <ProgressBar Value="{Binding Player1PointsLife}" Minimum="0" Maximum="8000"/>

Why when value exceeds maximum or minimun, it doens't update the UI anymore? How can I fix it? Thanks in advance.

为什么当值超过最大值或最小值时,它不再更新UI?我该如何解决?提前致谢。

UPDATE: Maybe I was not very clear. I mean, I set in progress bar value = 2000 (all right, updates de UI), then I set -1000 (it's correct, it mustn't show anything in the progress bar), and finally I set 6000 (here must updates the UI, but it isn't updating anymore).

更新:也许我不是很清楚。我的意思是,我设置进度条值= 2000(好吧,更新de UI),然后我设置-1000(它是正确的,它不能在进度条中显示任何内容),最后我设置6000(这里必须更新)用户界面,但它不再更新)。

2 个解决方案

#1


0  

Write a WPF converter so that if the value is >8000 or <0 it sets the value according to your requirement. Set the converter as follows in XAML:

编写WPF转换器,以便在值> 8000或<0时根据您的要求设置值。在XAML中将转换器设置如下:

<ProgressBar Value="{Binding Player1PointsLife, Converter={StaticResource **YourConverter**}}" Minimum="0" Maximum="8000"/> 

#2


0  

What should it do? It can't show the progress bar any more empty than fully empty or any more full than completely full. You can fix it by telling the progress bar what you want it to do. If you want it to appear, say, 85% full, set the value to 85% of the way from the minimum to the maximum.

它该怎么办?它不能显示进度条,而不是完全空,或者比完全填满更多。你可以通过告诉进度条你想要它做什么来修复它。如果要显示它,例如85%已满,请将值设置为从最小值到最大值的85%。

The usual way to do this for a stat in a game is to raise the maximum to the player's current maximum for that stat. If you allow the stat to go over the normal maximum for some reason (say a special power up), you have to decide how you want to display that. Maybe you can change the bar color and raise the maximum to the temporary maximum. Maybe you can add an additional bar to show the "overflow" power. Whatever works for your concept.

对游戏中的统计数据执行此操作的常用方法是将最大值提高到玩家当前最大值。如果由于某种原因(例如特殊启动)允许统计数据超过正常最大值,则必须决定如何显示该数据。也许你可以改变条形颜色并将最大值提高到临时最大值。也许你可以添加一个额外的栏来显示“溢出”的力量。什么适用于您的概念。

#1


0  

Write a WPF converter so that if the value is >8000 or <0 it sets the value according to your requirement. Set the converter as follows in XAML:

编写WPF转换器,以便在值> 8000或<0时根据您的要求设置值。在XAML中将转换器设置如下:

<ProgressBar Value="{Binding Player1PointsLife, Converter={StaticResource **YourConverter**}}" Minimum="0" Maximum="8000"/> 

#2


0  

What should it do? It can't show the progress bar any more empty than fully empty or any more full than completely full. You can fix it by telling the progress bar what you want it to do. If you want it to appear, say, 85% full, set the value to 85% of the way from the minimum to the maximum.

它该怎么办?它不能显示进度条,而不是完全空,或者比完全填满更多。你可以通过告诉进度条你想要它做什么来修复它。如果要显示它,例如85%已满,请将值设置为从最小值到最大值的85%。

The usual way to do this for a stat in a game is to raise the maximum to the player's current maximum for that stat. If you allow the stat to go over the normal maximum for some reason (say a special power up), you have to decide how you want to display that. Maybe you can change the bar color and raise the maximum to the temporary maximum. Maybe you can add an additional bar to show the "overflow" power. Whatever works for your concept.

对游戏中的统计数据执行此操作的常用方法是将最大值提高到玩家当前最大值。如果由于某种原因(例如特殊启动)允许统计数据超过正常最大值,则必须决定如何显示该数据。也许你可以改变条形颜色并将最大值提高到临时最大值。也许你可以添加一个额外的栏来显示“溢出”的力量。什么适用于您的概念。