Я сейчас в процессе написания пусковой установки, и я нахожусь на этапе прототипирования.Создание пусковой установки в WPF
Я действительно новичок в WPF, но не в архитектуре MVVM, однако я не уверен, как связать свой ViewModel с представлением CommandBox, потому что я использую методы в своей модели ViewModel, возможно, я смотрю на это из-за неправильного угла, поэтому, если я делаю что-то неправильно, просветите меня! :)
У меня есть следующие ViewModel, что в основном это действительно суть ракеты-носителя с точки зрения его ввода:
/// <summary>
/// Provides a buffer of characters in order to search for candidates that matches the buffer.
/// </summary>
public class CommandBufferViewModel : INotifyPropertyChanged
{
private readonly StringBuilder _input;
public CommandBufferViewModel()
{
_input = new StringBuilder();
}
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Deletes a character from the buffer.
/// </summary>
public void DeleteKey(int index, int length = 1)
{
_input.Remove(index, length);
OnPropertyChanged(nameof(DeleteKey));
}
/// <summary>
/// Adds a character to the buffer.
/// </summary>
public void ProcessKey(int index, char key)
{
_input.Insert(index, key);
OnPropertyChanged(nameof(ProcessKey));
}
/// <summary>
/// Returns results that matches the current buffer.
/// </summary>
/// <returns>Results that matches the current buffer.</returns>
public async Task<CommandResults> Search()
{
// NYI
return default(CommandResults);
}
protected virtual void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Идея заключается в том, что команды могут быть сохранены в удаленной базе данных или что-то для хранения вы может понравиться, а также локально.
The (вид CommandBox) TextBox выглядит следующим образом:
<TextBox
x:Class="Yalla.Launcher.Views.CommandBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:bs="clr-namespace:Yalla.Launcher.Behaviors"
mc:Ignorable="d"
Width="Auto" Height="Auto" VerticalContentAlignment="Center" BorderThickness="1">
<i:Interaction.Behaviors>
<bs:WatermarkBehavior Text="Enter Command... (type ? for help)" />
</i:Interaction.Behaviors>
</TextBox>