Skip to content

Commit 9cc4fd5

Browse files
committed
Modified readme file
1 parent e301bd4 commit 9cc4fd5

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed
2 KB
Loading
1.61 KB
Loading

README.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,101 @@
11
# How-to-disable-the-clear-button-in-numeric-textbox-in-Xamarin.Forms-UWP
2-
This article explains how to disable the clear button in UWP SfNumericTextBox in Xamarin
2+
3+
This article explains how to disable the clear button in UWP SfNumericTextBox in Xamarin.Forms
4+
5+
The SfNumericTextBox control is an advanced version of the Entry control that restricts input to numeric values. Its cancel button to clear the entire value in numeric textbox area as shown
6+
7+
![Output image of NumericTextBox with ClearButton](Outputs/NumericTextBoxWithClearButton.png)
8+
9+
If you want to get rid of this cancel button, you can disable the cancel button using custom renderer and the output will be like this
10+
11+
![Output image of NumericTextBox without ClearButton](Outputs/NumericTextBoxWithoutClearButton.png)
12+
13+
## Creating the above UI
14+
15+
You can achieve the above UI using the below code snippet
16+
17+
[C#]
18+
19+
```
20+
public class CustomNumericTextBox: SfNumericTextBox
21+
{
22+
23+
}
24+
```
25+
26+
[XAML]
27+
28+
```
29+
<StackLayout>
30+
31+
<local:CustomNumericTextBox Value="123" />
32+
33+
</StackLayout>
34+
```
35+
36+
[CustomNumericTextBoxRenderer_UWP]
37+
38+
```
39+
class CustomNumericTextBoxRenderer_UWP : SfNumericTextBoxRenderer
40+
{
41+
protected override void OnElementChanged(ElementChangedEventArgs<SfNumericTextBox> e)
42+
{
43+
base.OnElementChanged(e);
44+
if (Control != null)
45+
{
46+
Control.Loaded += Control_Loaded;
47+
}
48+
}
49+
50+
private void Control_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
51+
{
52+
53+
FindChildControl<Button>(Control, "DeleteButton");
54+
}
55+
public DependencyObject FindChildControl<T>(DependencyObject control, string ctrlName)
56+
{
57+
int childNumber = VisualTreeHelper.GetChildrenCount(control);
58+
for (int i = 0; i < childNumber; i++)
59+
{
60+
DependencyObject child = VisualTreeHelper.GetChild(control, i);
61+
FrameworkElement FrameElement = child as FrameworkElement;
62+
if (FrameElement == null) return null;
63+
64+
if ((FrameElement is Grid))
65+
{
66+
UIElement FrameElementChild = (FrameElement as Grid).Children[1];
67+
if (FrameElementChild is Grid)
68+
{
69+
UIElement CloseButton = (FrameElementChild as Grid).Children[6];
70+
if ((CloseButton as Button).Name == ctrlName)
71+
{
72+
(CloseButton as Button).Width = 0;
73+
(CloseButton as Button).Height = 0;
74+
}
75+
}
76+
return child;
77+
}
78+
else
79+
{
80+
DependencyObject nextLevel = FindChildControl<T>(child, ctrlName);
81+
if (nextLevel != null)
82+
return nextLevel;
83+
}
84+
}
85+
return null;
86+
}
87+
}
88+
```
89+
90+
## See also
91+
92+
[How to customize the colors in Xamarin.Forms SfNumericTextBox](https://help.syncfusion.com/xamarin/numeric-entry/colors)
93+
94+
[How to format the numeric value in Xamarin.Forms SfNumericTextBox](https://help.syncfusion.com/xamarin/numeric-entry/number-formatting)
95+
96+
[Available interaction in numeric control](https://help.syncfusion.com/xamarin/numeric-entry/events-and-interactivity)
97+
98+
99+
100+
101+

0 commit comments

Comments
 (0)