i want create textchanged event with binding but idk how to do. im making custom numeric up down and i want textchanged event but im using frame on main view help.
public class NumericUpDown : Frame
{
Grid _grid;
CustomNumericUpDownEntry _entry;
StackLayout _stackLayout;
Button _btnup;
Button _btndown;
double _value = 0, _maxValue = 60, _minValue = 0, _increaseValue = 1;
int _btnCornerRadius = 15;
Color _btnBackColor = Color.White;
public NumericUpDown() : base()
{
BindingContext = this;
_grid = new Grid();
_entry = new CustomNumericUpDownEntry();
_stackLayout = new StackLayout();
_btnup = new Button();
_btndown = new Button();
...
_stackLayout.Children.Add(_btndown);
_stackLayout.Children.Add(_btnup);
_grid.Children.Add(_entry);
_grid.Children.Add(_stackLayout);
Content = _grid;
}
...
}
<customitems:NumericUpDown
Margin="10,0"
BackgroundColor="Transparent"
BorderColor="red"
ButtonBackgroundColor="Purple"
ButtonCornerRadius="15"
CornerRadius="15"
HorizontalOptions="Center" />
CodePudding user response:
Is what you are looking for a way to access your custom control's bindable properties? With this properly setup, you could easily access something of the likes of OnTextChange if you want to bind a text value property.
If you want to simply have your buttons change the text however, you could also achieve this in your control's xaml.cs file by accessing your bindable properties from an ICommand attached directly to your down and up buttons.
CodePudding user response:
I found this and worked.
public NumericUpDown() : base()
{
BindingContext = this;
_entry = new CustomNumericUpDownEntry();
...
_entry.TextChanged = (sender, args) =>
{
OnTextChanged(args);
};
...
}
Public event
public event EventHandler<TextChangedEventArgs> TextChanged;
protected virtual void OnTextChanged(TextChangedEventArgs e)
{
EventHandler<TextChangedEventArgs> handler = TextChanged;
handler?.Invoke(this, e);
}
xaml
<customitems:NumericUpDown
x:Name="numRiskLimit"
...
TextChanged="numRiskLimit_TextChanged"
... />