我有一個有趣的問題,我一直試圖解決。基本上我有一個項目控件,它使用WrapPanel
,因爲它的ItemsPanel
可以模擬從幾個綁定字符串構建的段落。不過,有時候我需要強制休息一下,比如當我開始一個新的段落時,但是暫停進入TextBlock
DateTemplate
實際上並沒有在父級換行面板中放置休息。下面是代碼:使用包裝面板模板在物品控制中強制中斷
<ItemsControl ItemsSource="{Binding Fragments}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock
TextWrapping="Wrap"
Text="{Binding}"/> <!--If this text has a break it won't
propagate that break to the wrap panel,
but instead just in this text block which
causes the formatting to look wrong-->
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
這裏是片段一個簡單的定義,將顯示什麼我談論:
Fragments = new ObservableCollection<string>();
Fragments.Add("This is");
Fragments.Add("the first line, ");
Fragments.Add("it is very long and will drift to the ");
Fragments.Add("second line naturally since it is controlled by a wrap panel");
Fragments.Add("\n\r This I want to force to the line below where the line above ends");
Fragments.Add("rapid \n\r new \n\r lines");
我想這個流動的段落,只是繼續進行連接,但在遇到碰撞時遵守手動斷點。像這樣:
This is the first line, it is very long and will drift to the second line naturally since it is controlled by a wrap panel. This I want to force to the line below where the line above ends. rapid new lines
是否有任何理由你是不是串聯的字符串,然後將其綁定到一個簡單的文本框? – Kenneth
是否有任何理由不串聯字符串,然後將其綁定到一個簡單的文本框? – Kenneth
作者:「Break」你是不是指「NewLine」? –