, 나는
I는 각각 0.5 인치의 여백에 모든 라인의 시작 부분에있는 모든 탭을 변환 할 수 있습니다이 솔루션을 마련 할 수 있어요 및 단락에 동일한 텍스트를 추가합니다 계산 된 여백을 동일하게 적용
실행 굵게, 인라인 UI 컨테이너 등과 같은 기본 텍스트 인라인에 유용 할만큼 TextBlock을 사용할 수 없었습니다. TextBlock에서 단락을 추가하는 것이 더 복잡해 졌으므로 해결책을 만들었습니다. FlowDocument를 기반으로합니다.
결과
예를 아래에
는 동일한 첨부 할 수 있도록 FlowDocumentScrollViewer
또는 RichTextBox
또는 FlowDocumentReader
또는 일반 FlowDocument
내가 연결된 속성을 사용하여 솔루션을 만들었을 사용하여 동일한 보여 언급 된 것 또는 문서의 호스트를 추가 할 수 있습니다. IndentationProvider.Text
을 원하는 호스트로 설정하기 만하면됩니다.
XAML
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:l="clr-namespace:PreservingIndentationDemo"
Title="MainWindow"
Height="350"
Width="525">
<Window.Resources>
<sys:String x:Key="longString"
xml:space="preserve">	this is really long and wrapped
		another line this is also really long and wrapped
	one more line this is also really long and wrapped
another line this is also really long and wrapped
		another line this is also really long and wrapped
</sys:String>
</Window.Resources>
<Grid>
<FlowDocumentScrollViewer l:IndentationProvider.Text="{StaticResource longString}" />
<!--<RichTextBox l:TextToParaHelper.Text="{StaticResource longString}" IsReadOnly="True"/>-->
<!--<FlowDocumentReader l:TextToParaHelper.Text="{StaticResource longString}" />-->
<!--<FlowDocument l:TextToParaHelper.Text="{StaticResource longString}" />-->
</Grid>
</Window>
	
탭 숯불 지칭
IndentationProvider
Class IndentationProvider
Public Shared Function GetText(obj As DependencyObject) As String
Return DirectCast(obj.GetValue(TextProperty), String)
End Function
Public Shared Sub SetText(obj As DependencyObject, value As String)
obj.SetValue(TextProperty, value)
End Sub
' Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc...
Public Shared ReadOnly TextProperty As DependencyProperty = DependencyProperty.RegisterAttached("Text", GetType(String), GetType(IndentationProvider), New PropertyMetadata(Nothing, AddressOf OnTextChanged))
Private Shared Sub OnTextChanged(d As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim blocks As BlockCollection = Nothing
Dim rtb As RichTextBox = TryCast(d, RichTextBox)
If rtb IsNot Nothing Then
rtb.Document.Blocks.Clear()
blocks = rtb.Document.Blocks
End If
If blocks Is Nothing Then
Dim fd As FlowDocument = TryCast(d, FlowDocument)
If fd IsNot Nothing Then
fd.Blocks.Clear()
blocks = fd.Blocks
End If
End If
If blocks Is Nothing Then
Dim fdr As FlowDocumentReader = TryCast(d, FlowDocumentReader)
If fdr IsNot Nothing Then
fdr.Document = New FlowDocument()
blocks = fdr.Document.Blocks
End If
End If
If blocks Is Nothing Then
Dim fdr As FlowDocumentScrollViewer = TryCast(d, FlowDocumentScrollViewer)
If fdr IsNot Nothing Then
fdr.Document = New FlowDocument()
blocks = fdr.Document.Blocks
End If
End If
Dim newValue As String = TryCast(e.NewValue, String)
If Not String.IsNullOrWhiteSpace(newValue) Then
For Each line As String In newValue.Split(ControlChars.Lf)
Dim leftMargin As Double = 0
Dim newLine As String = line
While newLine.Length > 0 AndAlso newLine(0) = ControlChars.Tab
leftMargin += 0.5
newLine = newLine.Remove(0, 1)
End While
Dim marginInch As String = leftMargin & "in"
Dim marginDip As Double = CDbl(New LengthConverter().ConvertFromString(marginInch))
Dim para As New Paragraph(New Run(newLine)) With {.Margin = New Thickness(marginDip, 0, 0, 0)}
blocks.Add(para)
Next
End If
End Sub
End Class
데모
,536,913 , 어쩌면 그냥 왼쪽 '여백 그냥 모든 것을 왼쪽 공간을 갖고 싶어, 그렇지 않은 경우, 공간 = 당신의 TextBlock의에` "보존"실제로 문자열에 탭이 있다면 63,210
이 demo project
을 시도, XML'때리는 수 '당신이 찾고있는 비주얼을 완성 할 수 있을까요? –
문제는 탭을 유지하는 것이 아니라 제대로 표시되는 것입니다. 텍스트가 여러 줄로 줄을 감쌀 때 줄을 들여 씁니다. 현재 줄 바꿈 텍스트의 두 번째 줄 (등)은 왼쪽 가장자리에 다시 붙습니다. – simonalexander2005
여기에 여백이 필요할 수 있습니다. 탭을 실행하지 못할 수도 있습니다. – pushpraj