Silverlight сильно отличается от используемой вами консольной системы макетов.Во многих случаях я бы посчитал Silverlight простым, но, конечно, он не очень хорош в качестве замены пользовательского интерфейса, который использует printf и символы с абсолютным позиционированием.
Я бы действительно посоветовал вам пройти несколько из этих уроков:*
http://www.silverlight.net/learn/quickstarts/
Ниже приведен полный пример из конца в конец простого простого консольного приложения, которое я создал вместе (в лучшем случае элементарный).Есть много способов выполнить то, что я сделал ниже.
Он демонстрирует один способ косвенного доступа к элементам пользовательского интерфейса из другого класса.Я бы предложил не подвергать элементы пользовательского интерфейса напрямую другим классам, как я это продемонстрировал.
<UserControl x:Class="SL1Test.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" FontSize="16"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="Black">
<Grid.RowDefinitions>
<!-- Give first row max height -->
<RowDefinition Height="*"/>
<!-- Give second row as little as needed-->
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!--A giant textblock, in a scrolling area-->
<ScrollViewer
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto">
<TextBlock x:Name="tbMyConsole" Foreground="Green"
FontFamily="Courier New" FontWeight="Bold"/>
</ScrollViewer>
<Grid Grid.Row="1" >
<Grid.ColumnDefinitions>
<!-- Give first column max width -->
<ColumnDefinition Width="*"/>
<!-- Give second column as little as needed-->
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="txtConsoleInput" Foreground="Green" Background="Black"
SelectionForeground="Black"
CaretBrush="Green"
SelectionBackground="YellowGreen"/>
<Button Grid.Column="1" x:Name="btnSend">Send</Button>
</Grid>
</Grid>
</UserControl>
И выделенный код C #:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace SL1Test
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
btnSend.Click += new RoutedEventHandler(btnSend_Click);
txtConsoleInput.KeyUp += new KeyEventHandler(txtConsoleInput_KeyUp);
AutoTicker ticker = new AutoTicker("AutoTicker", this);
}
void txtConsoleInput_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
e.Handled = true;
ProcessSend();
}
}
void btnSend_Click(object sender, RoutedEventArgs e)
{
ProcessSend();
}
private void ProcessSend()
{
string input = txtConsoleInput.Text;
ProcessInput(input);
txtConsoleInput.Text = "";
}
public void ProcessInput(string input)
{
if (!string.IsNullOrWhiteSpace(input))
{
input = DateTime.Now.ToLocalTime() + "> " + input + "\n";
tbMyConsole.Text = tbMyConsole.Text + input;
txtConsoleInput.Text = "";
}
}
}
}
И, наконец, второй класс, который отправляет результатыобратно в первый класс:
using System;
using System.Windows.Threading;
namespace SL1Test
{
public class AutoTicker
{
private MainPage _page;
private string _caption;
public AutoTicker(string caption, MainPage page)
{
this._page = page;
this._caption = caption;
// start a timer to send back fake input
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(2);
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
_page.ProcessInput(string.Format("{0} @ {1}",
this._caption,
DateTime.Now.ToLongTimeString()));
}
}
}