In TextBox showing float propertie value - c#

So i have a float variable in the Application Settings Properties.Settings.Default.flvalue, now i want to show this in a TextBox and also edit and save afterwards.
To Show it i have to convert it toString() but then i want to Format it like: 1.23
unfortunately this is not working. Is there any NumberBox in C# WPF or better way to bind the settings variable into a TextBox?
_flvalue.Text = Properties.Settings.Default.flvalue.ToString();
<TextBox x:Name="_flvalue" Text="{StringFormat={}{0:#,0.0}}""></TextBox>

Related

In Unity3D inputField is treated as a placeholder

My goal: Place the value from sqlite database into the inputField as text. I want the user to be able to update the record/value of that database. Baically, I am trying to make a note app kinda like note on iPhone.
My issue: The text shows up in the field inside the text and contentfield, including the input cursor/caret. When the user clicks on the text field it resets everything to empty.
What I have tried: I created a script that will change the value of text inside the inputField to a value fetched from the database. The text gets updated as expected. Then as soon as I or other users press on the inputField the value dissapears, similar to how a placeholder works. However, I want the value to stay in place so the user can edit it.
the code:
TextMeshProUGUI contenttext =
input1.transform.Find("Text").GetComponentInChildren<TextMeshProUGUI>();
contenttext.text = source;
This is suppose to update the text component, which is a child of text area which is a child of contentfield. Here are before and after pictures of the inspector.
You need to set the value in the .text field of the TMP_InputField, not the TextMeshProUGUI
input1.transform.Find("Text").GetComponentInChildren<TMP_InputField>().text = source;

How to change the precision of UWP Telerik RadDataGrid DataGridNumericalColumn editor

I'm using the Telerik UWP RadDatagrid inside my application. There's a column that contains integers in the item source that is bound to the datagrid. This displays correctly i.e. 1 displays as 1. However the cell editor seems to use a double rather than an int. Therefore if i click away from the cell with 1 entered rather than 1.00 it doesn't commit the change.
Is there a way to specify the precision of the inline editor to be an integer rather than a double for the DataGridNumericalColumn ?
The editor of the Numerical Column is a
RadNumericBox. The value format is defined by the ValueFormat property, that the default value is {0,0:N2} defined by RadNumericBox.cs. Which will just show like "1:00". Actually update the ValueFormat to {}{0:N0} will meet your requirements. You could add a RadNumericBox to check the result.
<input:RadNumericBox
x:Name="numericBox2"
AllowNullValue="False"
ValueFormat="{}{0:N0}"
Watermark="Fill in the field" />
<input:RadNumericBox
x:Name="numericBox3"
AllowNullValue="False"
ValueFormat="{}{0:N2}"
Watermark="Fill in the field" />
Since the Numerical Column does't provide a ValueFormat property, so unfortunately you may need to re-write the Telerik package to implement your own DataGridNumericalColumn (Or simple to just change the default value for RadNumercBox but may be not recommended). For detail implementation please try it yourself.

Invalid TextBox values gets reset by ComboBox's DataBinding

Situation: A C# Windows Forms application with a TextBox and a ComboBox. AutoValidate is set to EnableAllowFocusChange.
The TextBox represents and is shown as a percentage value e.g. "10 %" which is stored as an int. Both input controls are data bound, the TextBox with a parsing and formatting ConvertEventHandler as well as a Validating CancelEventHandler.
When entering an invalid input like "abc" and leaving the control: My Validation is performed and fails (e.Cancel = true, ErrorProvider ..). And my parsing fails (e.Value stays "abc").
Problem: When I now change the value of the ComboBox and leave it (lost focus/perform validation) or do a ValidateChildren, my format function is called with the last valid percentage value and the wrong input is lost.
Stacktrace: The problem is triggered by a ReportPropertyChanged of the ComboBox and leads to Binding.PushData, FormatObject and OnFormat -> Which calls my format function with the original value.
I want my TextBox to stay invalid and no magical reset. What can I do to prevent a value reset? Or what did I do wrong?
Thanks!

C# /windows forms: linking trackbar and textfield with a factor

linking a trackbar and a textfield is very easy in windows forms.
it is like this:
textBox.DataBindings.Add("Text", trackBar, "Value");
the problem is, that trackbars only allow for integer values but i want to have floating point values.
so i usually just divide the value by 100, since on the trackbar the value is not directly visible to the user.
but in the textbox it is.
so is it possible to link these two with a factor of 100?
thanks!
The line of code you have adds a Binding object to the text box's DataBindings collection.
The Binding class has events called Format and Parse, which you can use to perform the division (the Format event takes a value from the trackbar and formats it for the text box) and the multiplication (the Parse event takes a value from the text box and scales it for the trackbar).
You can use intermediate variables like below:
public double v{set;get;}
public int v100
{
set { v = value / 100D; }
get { return (int)(v* 100D); }
}
and blind them with Controls.
trackBar.DataBindings.Add(new Binding("Value", PtParams, "v100"));
textBox.DataBindings.Add(new Binding("Text", PtParams, "v"));

Can you have different item-text and item-values when using ObjectDataProvider?

When setting the source of an items control (ComboBox, for example), is it possible to have the SelectedValue property be different than the text that is displayed. I have a ComboBox that I want to display only the time portion of a DateTime, and have the value of each item be the DateTime object itself.
Thanks!
The combobox has an ItemStringFormat property that dictates how items are displayed in the dropdown and textbox parts of the control.
In the case of this example from the MSDN the SelectedValue will be a datetime objects, while the control itself will display the formatted strings.
See here for how to create the format string that will work for your problem. (Something like "HH:mm:ss" I'd guess)

Categories

Resources