我想进行转换,将Decimal转换为Int。看看我的代码:十进制到Int转换器
<ProgressBar Margin="0,10,0,10"
Grid.Row="2" Grid.ColumnSpan="3" IsIndeterminate="False" Height="10"
Maximum="{Binding SavingGoal, Converter={StaticResource DecimalToInt}}" Value="{Binding Balance, Converter={StaticResource DecimalToInt}}"/>
这里,它是在绑定指着:
newGoal.SavingGoal = Convert.ToDecimal(SavingsAmountsTextBox.Text);
newGoal.Balance = 0;
这里是类:
public decimal SavingGoal { get; set; }
public decimal Balance { get; set; }
所以我的问题是,我不知道如何使用IValueConverter来适应我的情况。我想将我的UserControl分解的小数转换为int,并使进度条最终工作。
你能告诉你的'DeciamlToInt'转换器? – Romasz
您的转换器需要通过储蓄目标以及余额。 IValueConverter接口确实指定了一个参数,但增加一个“派生属性”来计算,可能会更直截了当。类似于'public int PercentOfGoal {get {return(int)(Balance/SavingsGoal)* 100; }}',然后将'Value'绑定到那个。 –
在我的转换器上没有任何东西的时候。现在我在Convert方法中做了这样的事情: 'if(value is decimal){ return System.Convert.ToInt32(value); } return false;' –