|
<!-- |
|
Auther : Nia Tomonaka |
|
Twitter : https://twitter.com/nia_tn1012 |
|
--> |
|
|
|
<!-- 分離コードは初期化のみです。 --> |
|
<Window x:Class="WPFHaiku.MainWindow" |
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|
xmlns:loc="clr-namespace:WPFHaiku" |
|
Title="俳句" Height="500" Width="230" ResizeMode="NoResize"> |
|
|
|
<Window.Resources> |
|
<!-- 俳句のテキストの設定です。 --> |
|
<Style x:Key="HaikuText" TargetType="TextBlock"> |
|
<Setter Property="FontSize" Value="50"/> |
|
<Setter Property="FontFamily" Value="HGSGyoshotai"/> |
|
<Setter Property="HorizontalAlignment" Value="Center"/> |
|
</Style> |
|
<!-- 文字列を縦書きに変換するコンバーターです。 --> |
|
<loc:HaikuConverter x:Key="HaikuConverter"/> |
|
</Window.Resources> |
|
|
|
<Grid Background="DarkGreen"> |
|
|
|
<!-- 上部を俳句、下部を入力ボックスとします。 --> |
|
<Grid.RowDefinitions> |
|
<RowDefinition Height="*"/> |
|
<RowDefinition Height="30"/> |
|
</Grid.RowDefinitions> |
|
|
|
<!-- 俳句を入力するテキストボックスです。 --> |
|
<TextBox Grid.Row="1" x:Name="HaikuInput" Margin="5"/> |
|
|
|
<!-- 俳句を表示するエリアです。 --> |
|
<Border Grid.Row="0"> |
|
<Grid Margin="10" Background="Ivory"> |
|
<!-- |
|
HaikuConverterを使って、HaikuInputに入力した文字列をカンマで区切り、 |
|
要素の並びを反転した時のIEnumerable<string>型のリストに変換します。 |
|
これをItemsControlのItemsSourceにバインディングし、StackPanelを使って |
|
TextBlockを横方向に並べます。 |
|
--> |
|
<ItemsControl ItemsSource="{Binding Text, Converter={StaticResource HaikuConverter}, |
|
ElementName=HaikuInput, Mode=OneWay}"> |
|
<ItemsControl.ItemsPanel> |
|
<ItemsPanelTemplate> |
|
<StackPanel Orientation="Horizontal" |
|
HorizontalAlignment="Center"/> |
|
</ItemsPanelTemplate> |
|
</ItemsControl.ItemsPanel> |
|
<ItemsControl.ItemTemplate> |
|
<DataTemplate> |
|
<TextBlock Style="{StaticResource HaikuText}" |
|
Margin="5" Text="{Binding}"/> |
|
</DataTemplate> |
|
</ItemsControl.ItemTemplate> |
|
</ItemsControl> |
|
</Grid> |
|
</Border> |
|
</Grid> |
|
</Window> |
|
|
|
<!-- |
|
Haiku2.xaml( For WPF ) |
|
Copyright (c) 2014-2023 Nia T.N. Tech Lab. / Chronoir.net. |
|
This software is released under the MIT License. |
|
http://opensource.org/licenses/mit-license.php |
|
--> |
GitHubのアカウント統合のため、Myoga1012→Nia-TN1012に移行しました。
旧URL: https://gist.github.com/Myoga1012/c61584bf5a408af1129c