Created
July 17, 2010 02:16
-
-
Save Vaccano/479176 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl x:Class="IsAProgrammer.QuestionAsker" | |
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" d:DesignHeight="364" d:DesignWidth="470" | |
DataContext="{Binding QuestionAskerViewModel}"> | |
<Grid x:Name="LayoutRoot" Background="White"> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="*"/> | |
</Grid.ColumnDefinitions> | |
<Grid.RowDefinitions> | |
<RowDefinition Height=".2*" /> | |
<RowDefinition Height=".7*" /> | |
<RowDefinition Height=".1*" /> | |
</Grid.RowDefinitions> | |
<TextBlock Grid.Row="0" Margin="5" Text="{Binding CurrentQuestion.QuestionText}"/> | |
<TextBox Grid.Row="1" Name="CodeBox" Text="{Binding CurrentQuestion.AnswerText}" Margin="5" TextWrapping="Wrap" AcceptsReturn="True" CaretBrush="Black" KeyDown="CodeBox_KeyDown" /> | |
</Grid> | |
</UserControl> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Controls; | |
using System.Windows.Input; | |
using IsAProgrammer.QuestionService; | |
namespace IsAProgrammer | |
{ | |
public partial class QuestionAsker : UserControl | |
{ | |
public QuestionAskerVM QuestionAskerViewModel { get; set; } | |
public QuestionAsker() | |
{ | |
InitializeComponent(); | |
QuestionAskerViewModel = new QuestionAskerVM(); | |
DataContext = QuestionAskerViewModel; | |
} | |
private const string Tab = " "; | |
private void CodeBox_KeyDown(object sender, KeyEventArgs e) | |
{ | |
if (e.Key == Key.Tab) | |
{ | |
int selectionStart = CodeBox.SelectionStart; | |
CodeBox.Text = String.Format("{0}{1}{2}", | |
CodeBox.Text.Substring(0, CodeBox.SelectionStart), | |
Tab, | |
CodeBox.Text.Substring(CodeBox.SelectionStart + CodeBox.SelectionLength, (CodeBox.Text.Length) - (CodeBox.SelectionStart + CodeBox.SelectionLength)) | |
); | |
e.Handled = true; | |
CodeBox.SelectionStart = selectionStart + Tab.Length; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Windows; | |
using IsAProgrammer.QuestionService; | |
namespace IsAProgrammer | |
{ | |
public class QuestionAskerVM: DependencyObject | |
{ | |
public QuestionAskerVM() | |
{ | |
QuestionServiceClient client = new QuestionServiceClient(); | |
client.GetQuestionCompleted += QuestionRecieved; | |
client.GetQuestionAsync(); | |
} | |
private void QuestionRecieved(object sender, GetQuestionCompletedEventArgs e) | |
{ | |
CurrentQuestion = e.Result; | |
} | |
// This is the current question. | |
public Question CurrentQuestion | |
{ | |
get { return (Question)GetValue(CurrentQuestionProperty); } | |
set { SetValue(CurrentQuestionProperty, value); } | |
} | |
public static readonly DependencyProperty CurrentQuestionProperty = DependencyProperty.Register("CurrentQuestion", typeof(Question), typeof(QuestionAskerVM), new PropertyMetadata(null)); | |
// This is the current answer. | |
public Answer CurrentAnswer | |
{ | |
get { return (Answer)GetValue(CurrentAnswerProperty); } | |
set { SetValue(CurrentAnswerProperty, value); } | |
} | |
public static readonly DependencyProperty CurrentAnswerProperty = DependencyProperty.Register("CurrentAnswer", typeof(Answer), typeof(QuestionAskerVM), new PropertyMetadata(null)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment