English 中文(简体)
将百分率输入文字箱
原标题:Entering percentage into text box multiplies value by 100

我在《银灯》中摘录如下文箱:

<TextBox Text="{Binding Model.PercentOfSale, Mode=TwoWay, StringFormat=p}"/>

这里的定义是:<> > > > >>> >> > > > > > > > >

The display in the text box is as expected:

0.00 %

然而,当我进入新的价值(倡议15)时,我得到:

1 500.00 %

因此,价值正在乘以100(正确无误)。

我的使用者不愿意把价值输入0.15,因此,我需要做些什么来接受15%而不是1 500%?

我在这里看到其他问题,如:

How to set WPF string format as percent wihout multiplying by 100?
Format decimal for percentage values?

但是,所提供的解决办法对我来说并不可行。

最佳回答

What about using Converters?
If you don t want to change input values than you can convert then.
Here is example of converters usage.

问题回答

我最后修改了财产集束,以便修改价值:

private decimal percentOfSale;
public decimal PercentOfSale
{
    get
    {
        return percentOfSale;
    }
    set
    {
        percentOfSale = value / 100;
        RaisePropertyChangedEvent("PercentOfSale");
    }
}

因此,我的XAML成为:

<TextBox Text="{Binding PercentOfSale, Mode=TwoWay, StringFormat=p}"/>

我的模型是:

this.percentOfSale = Model.PercentOfSale;

注意到“p”这一较低情况——这避免了初始设置的扩大,使有约束力的工作中的<编码>规范格式<>,并且当从《国际交易日志》中确定价值时,该数值也相应比额表。

然后,我想要挽救数据:

Model.PercentOfSale = this.percentOfSale;

我实际上发现,这些百分比被储存为0至100(而不是0至1)的数值——它不是我的数据模型和格式;我应该首先检查,因此,我需要扩大最初设定的价值:

this.PercentOfSale = Model.PercentOfSale;

注:“P”。

以及储蓄:

Model.PercentOfSale = this.percentOfSale * 100;

to bring it back into line with the data as stored in the database.





相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签