我需要以非常特定的格式向用户呈现一些数据,我希望看起来像这样:
+- Window 1 --------------------------+ +- Window 2 ----------+
| This is some text that is being | | Yet more stuff |
| output for the user. | | |
| | | |
+-------------------------------------+ +---------------------+
+- Window 3 ----------------+ +- Window 4 --------------------+
| Yoiks! | | Blah blah blah |
| To eternity and beyond... | | |
| | | |
+---------------------------+ +-------------------------------+
将会有许多这些项目,所有项目都有不同的标题,并且它们将具有固定的大小(每个部分的大小不同,但每个部分的大小都是固定的)。这些部分中的文字将是固定字体(如Courier),而不是成比例。
我已经设置了WPF StackPanels,以便按照我想要的方式正确安排这些控件。我需要知道的是用于实际内容的最佳控件(一个漂亮的框架和标题,其中包含固定大小的文本)。
另一件事,我需要能够在控件内强调一个或多个字符。在我的Java版本中,我能够使用HTML来执行此操作。如果文本能够具有其他属性(如前景色和背景色)也很好,但这并非绝对必要。
答案 0 :(得分:3)
您应该将布局问题划分为多个不同的层。 首先是你的“窗户”有多大。在这里,我要么使用一堆堆栈面板或网格彼此。这可能有点重量,但它会使你的布局非常灵活。
然后我会使用GroupBoxes来获得“标题窗口”外观。然后,您可以将任何内容设置为其内容。
这样的东西?
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="3*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<GroupBox BorderThickness="1" BorderBrush="Black" Header="Window 1" Grid.Column="0">
<TextBlock>This is some text that is being output for the user.</TextBlock>
</GroupBox>
<GroupBox BorderThickness="1" BorderBrush="Black" Header="Window 2" Grid.Column="1">
<TextBlock>Yet more stuff</TextBlock>
</GroupBox>
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<GroupBox BorderThickness="1" BorderBrush="Black" Header="Window 3" Grid.Column="0">
<TextBlock>
Yoiks!
To eternity and beyond...
</TextBlock>
</GroupBox>
<GroupBox BorderThickness="1" BorderBrush="Black" Header="Window 4" Grid.Column="1">
<TextBlock>Blah blah blah</TextBlock>
</GroupBox>
</Grid>
</Grid>
答案 1 :(得分:1)
有无数种方法可以做到这一点。 WPF控件非常灵活。
<Border Width="320" Height="200" Canvas.Left="40" Canvas.Top="72" BorderThickness="1" BorderBrush="Black">
<DockPanel>
<Label Content="Window 1" VerticalAlignment="Top" Width="320" Background="#FFFFE58B" DockPanel.Dock="Top" />
<RichTextBox DockPanel.Dock="Bottom">
<FlowDocument>
<Paragraph><Run Text="I am a fancy textbox"/></Paragraph>
</FlowDocument>
</RichTextBox>
</DockPanel>
</Border>
您应该能够在富文本框中以格式化方式执行任何操作