Skip to content

Commit

Permalink
TimetableEditorItem基本完成,完成了它的几个属性,并且完善了它的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
STBBRD committed Nov 11, 2023
1 parent b6fee05 commit 93287cf
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
22 changes: 21 additions & 1 deletion ZongziTEK_Blackboard_Sticker/Resources/TimeTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public TimeTextBox()
PreviewTextInput += TimeTextBox_PreviewTextInput;
TextChanged += TimeTextBox_TextChanged;
SelectionChanged += TimeTextBox_SelectionChanged;
GotFocus += TimeTextBox_GotFocus;
PreviewMouseDown += TimeTextBox_PreviewMouseDown;

Text = "00:00";
TextAlignment = System.Windows.TextAlignment.Center;
}

Expand Down Expand Up @@ -84,7 +88,7 @@ private void TimeTextBox_TextChanged(object sender, TextChangedEventArgs e)
int textLength = Text.Length;

// 当光标在最后一个数字的后面时,将光标移到第一个数字前面
if (caretIndex > textLength)
if (caretIndex >= textLength)
{
CaretIndex = 0;
}
Expand Down Expand Up @@ -117,5 +121,21 @@ private void TimeTextBox_SelectionChanged(object sender, RoutedEventArgs e)
{
if (SelectionLength != 0) SelectionLength = 0; //防止文本被选中
}

private void TimeTextBox_GotFocus(object sender, RoutedEventArgs e)
{
CaretIndex = 0;
CaretIndex = 0;
CaretIndex = 0;
}

private void TimeTextBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (!IsKeyboardFocusWithin)
{
e.Handled = true;
Focus();
}
}
}
}
16 changes: 12 additions & 4 deletions ZongziTEK_Blackboard_Sticker/Resources/TimetableEditorItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>

<TextBox BorderThickness="0" Grid.Column="0" Margin="8,6" Text="语文" TextAlignment="Center" VerticalContentAlignment="Center" Background="{x:Null}"/>
<local:TimeTextBox BorderThickness="0" Grid.Column="1" Margin="8,6" Text="07:25" VerticalContentAlignment="Center" Background="{x:Null}"/>
<local:TimeTextBox BorderThickness="0" Grid.Column="2" Margin="8,6" Text="08:55" VerticalContentAlignment="Center" Background="{x:Null}"/>
<Grid Grid.Column="0" Margin="8,6">
<TextBlock x:Name="TextBlockHintSubject" Text="在此输入课程名称" Foreground="#CC000000" FontSize="14"
TextAlignment="Center" VerticalAlignment="Center"/>
<TextBox x:Name="TextBoxSubject" BorderThickness="0"
Text="{Binding Subject, RelativeSource={RelativeSource AncestorType=UserControl}}"
TextAlignment="Center" VerticalContentAlignment="Center" Background="{x:Null}"
GotFocus="TextBoxSubject_GotFocus" LostFocus="TextBoxSubject_LostFocus"/>
</Grid>
<local:TimeTextBox BorderThickness="0" Grid.Column="1" Margin="8,6"
Text="{Binding StartTime, RelativeSource={RelativeSource AncestorType=UserControl}}" VerticalContentAlignment="Center" Background="{x:Null}"/>
<local:TimeTextBox BorderThickness="0" Grid.Column="2" Margin="8,6"
Text="{Binding EndTime, RelativeSource={RelativeSource AncestorType=UserControl}}" VerticalContentAlignment="Center" Background="{x:Null}"/>
</Grid>
</Border>
</UserControl>
40 changes: 40 additions & 0 deletions ZongziTEK_Blackboard_Sticker/Resources/TimetableEditorItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,45 @@ public TimetableEditorItem()
{
InitializeComponent();
}

public static readonly DependencyProperty SubjectProperty =
DependencyProperty.Register("Subject", typeof(string), typeof(TimetableEditorItem));

public string Subject
{
get { return (string)GetValue(SubjectProperty); }
set { SetValue(SubjectProperty, value); }
}

public static readonly DependencyProperty StartTimeProperty =
DependencyProperty.Register("StartTime", typeof(string), typeof(TimetableEditorItem));

public string StartTime
{
get { return (string)GetValue(StartTimeProperty); }
set { SetValue(StartTimeProperty, value); }
}

public static readonly DependencyProperty EndTimeProperty =
DependencyProperty.Register("EndTime", typeof(string), typeof(TimetableEditorItem));

public string EndTime
{
get { return (string)GetValue(EndTimeProperty); }
set { SetValue(EndTimeProperty, value); }
}

private void TextBoxSubject_GotFocus(object sender, RoutedEventArgs e)
{
TextBlockHintSubject.Visibility = Visibility.Hidden;
}

private void TextBoxSubject_LostFocus(object sender, RoutedEventArgs e)
{
if(TextBoxSubject.Text == "")
{
TextBlockHintSubject.Visibility = Visibility.Visible;
}
}
}
}

0 comments on commit 93287cf

Please sign in to comment.