You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose to split up EditBox.cs into two halves, first of which works without GridView View requirement as the following. Second half would inherit the first.
Sorry, new to GitHub, not sure how this works.
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows;
using System.Windows.Documents;
namespace EditBoxControlLibrary
{
public class EditBoxBase : TextBlock
{
#region Static Constructor
static EditBoxBase()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(EditBoxBase), new FrameworkPropertyMetadata(typeof(EditBoxBase)));
}
#endregion
#region Public Methods
public EditBoxBase()
{
this.Loaded += EditBoxBase_Loaded;
_textBox = new TextBox();
_textBox.KeyDown += new KeyEventHandler(OnTextBoxKeyDown);
_textBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(OnTextBoxLostKeyboardFocus);
}
bool bLoadedFinished = false;//Not sure why EditBoxBase_Loaded fires twice ... 20190711
private void EditBoxBase_Loaded(object sender, RoutedEventArgs e)
{
if (bLoadedFinished) return;
bLoadedFinished = true;
TextBlock textBlock = this as TextBlock;
this.MouseEnter += EditBoxBase_MouseEnter;
this.MouseLeave += EditBoxBase_MouseLeave;
this.MouseUp += EditBoxBase_MouseUp;
_adorner = new EditBoxBaseAdorner(textBlock, _textBox);
AdornerLayer layer = AdornerLayer.GetAdornerLayer(textBlock); // fails on getting adorner if this is in constructor
layer.Add(_adorner);
}
#endregion
#region Protected Methods
protected void EditBoxBase_MouseEnter(object sender, MouseEventArgs e)
{
if (!IsEditing)
{
_canBeEdit = true;
}
}
protected void EditBoxBase_MouseLeave(object sender, MouseEventArgs e)
{
_isMouseWithinScope = false;
_canBeEdit = false;
}
protected void EditBoxBase_MouseUp(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Right || e.ChangedButton == MouseButton.Middle)
return;
if (!IsEditing)
{
if (!e.Handled && (_canBeEdit || _isMouseWithinScope))
{
IsEditing = true;
}
}
}
#endregion
#region Public Properties
#region IsEditing
public static DependencyProperty IsEditingProperty =
DependencyProperty.Register(
"IsEditing",
typeof(bool),
typeof(EditBoxBase),
new FrameworkPropertyMetadata(false));
public bool IsEditing
{
get { return (bool)GetValue(IsEditingProperty); }
private set
{
SetValue(IsEditingProperty, value);
_adorner.UpdateVisibilty(value);
}
}
#endregion
#endregion
#region Private Methods
private void OnTextBoxKeyDown(object sender, KeyEventArgs e)
{
if (IsEditing && (e.Key == Key.Enter || e.Key == Key.F2))
{
IsEditing = false;
_canBeEdit = false;
}
}
private void OnTextBoxLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
IsEditing = false;
}
#endregion
#region private variable
private EditBoxAdorner _adorner;
private FrameworkElement _textBox;
private bool _canBeEdit = false;
private bool _isMouseWithinScope = false;
#endregion
}
}
The text was updated successfully, but these errors were encountered:
@nick2893 commented on Tue Jul 16 2019
I propose to split up EditBox.cs into two halves, first of which works without GridView View requirement as the following. Second half would inherit the first.
Sorry, new to GitHub, not sure how this works.
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows;
using System.Windows.Documents;
namespace EditBoxControlLibrary
{
}
The text was updated successfully, but these errors were encountered: