Here BindableBase class i used from the prism if you are not using Prism you will not get BindableBase class you have to implement INotifyPropertyChanged
public class CharInfo : BindableBase
{
private string _charecter;
public string Charecter
{
get { return _charecter; }
set
{
_charecter = value;
SetProperty(ref _charecter, value);
}
}
private int _position;
public int Position
{
get { return _position; }
set
{
_position = value;
SetProperty(ref _position, value);
}
}
}
Add these Property, Command and method to ViewModel
private ObservableCollection<CharInfo> matchedInfo = new ObservableCollection<CharInfo>();
public ObservableCollection<CharInfo> MatchedInfo { get => matchedInfo; set => SetProperty(ref matchedInfo, value); }
private string text;
public string Text { get => text; set => SetProperty(ref text, value); }
private string charToMatch;
public string CharToMatch { get => charToMatch; set => SetProperty(ref charToMatch, value); }
private ICommand matchCharCommand;
public ICommand MatchCharCommand
{
get
{
if (matchCharCommand == null)
{
matchCharCommand = new DelegateCommand(MatchChar);
}
return matchCharCommand;
}
}
private void MatchChar()
{
MatchedInfo.Clear();
if (!string.IsNullOrEmpty(Text) && !string.IsNullOrEmpty(CharToMatch))
{
for (int i = 0, pos = -1; i < Text.Length;)
{
pos = Text.IndexOf(CharToMatch, pos + 1);
if (pos < 0)
break;
MatchedInfo.Add(new CharInfo { Charecter = charToMatch, Position = pos });
Comments
Post a Comment