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
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace WpfApp2
{
/// <summary>
/// MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
ViewModel mViewModel = new ViewModel();
public MainWindow()
{
InitializeComponent();
this.DataContext = mViewModel;
}
private void TextBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
mViewModel.setEditStatus((sender as TextBox).Text, true);
}
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
mViewModel.setEditStatus((sender as TextBox).Text, false);
}
}
public class Item : DataBindingBase
{
private string _name = "";
private bool _isEditNow = false;
public string Name { get { return _name; } set { _name = value; NotifyPropertyChanged(nameof(Name)); } }
public bool IsEditNow { get { return _isEditNow; } set { _isEditNow = value; NotifyPropertyChanged(nameof(IsEditNow)); } }
}
public class ViewModel : DataBindingBase
{
public ViewModel()
{
this.ItemList.Add(new Item() { Name = "Test1" });
this.ItemList.Add(new Item() { Name = "Test2" });
this.ItemList.Add(new Item() { Name = "Test3" });
this.ItemList.Add(new Item() { Name = "Test4" });
}
private ObservableCollection<Item> _itemList = new ObservableCollection<Item>();
public ObservableCollection<Item> ItemList
{
get
{
return _itemList;
}
set
{
_itemList = value;
NotifyPropertyChanged(nameof(ItemList));
}
}
public void setEditStatus(string pName, bool pIsEditNow)
{
if (string.IsNullOrEmpty(pName) == false)
{
if (this.ItemList.FirstOrDefault() != null)
{
if (this.ItemList.Select(x => x.Name).Contains(pName) == true)
{
this.ItemList.FirstOrDefault(x => x.Name == pName).IsEditNow = pIsEditNow;
}
}
}
}
}
public class DataBindingBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(string pPropertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(pPropertyName));
}
}
}
}
I can/cannot ...
I can edit with byte character (ex. 0-9, a-z, A-Z). But I cannot edit with double-byte character (ex. Japanese 'テスト').
I tried this pattern with reference to this article.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Details
I want to ListBox with editable TextBox. And I use this sourcecode.
The Minimum sourcecode
```I can/cannot ...
I can edit with byte character (ex. 0-9, a-z, A-Z). But I cannot edit with double-byte character (ex. Japanese 'テスト').
I tried this pattern with reference to this article.
My sourcecode is wrong? Thank you very much.
Beta Was this translation helpful? Give feedback.
All reactions