I am trying to create a custom Output Window for my software that is bound to my ViewModel. Usually in the past I have always used a TextBox and used the appendText()
method to write to the Output Window. Of course with a ViewModel and trying to bind to a Textbox, it seems you can only Bind to the Text
property. Below is what I am trying to do:
XAML:
<TextBox Text="{Binding Output}"></TextBox>
C#
public class ViewModel : DependencyObject
{
public static readonly DependencyProperty OutputProperty = DependencyProperty.Register("Output", typeof(ObservableCollection<string>), typeof(MVVMTestViewModel), new UIPropertyMetadata(null));
public ObservableCollection<string> Output
{
get
{
return (ObservableCollection<string>)GetValue(OutputProperty);
}
set
{
SetValue(OutputProperty, value);
}
}
public ViewModel()
{
Output = new ObservableCollection<string>();
}
public void OutputMessage(string message)
{
Output.Add(message);
}
}
Of course this is not possible because Text cannot be assigned to an Observable Collection.
Note: I could use a ListView, or a ListBox and use an observable collection. But I do not like the selection mode. I like to be able to highlight the text of a TextBox so that I can copy and paste it out of the Window. The isReadOnly
property allows me to do this fairly easily.
Is there an easy way to do this? Another Control I haven't though of perhaps?