TextBox의 style 속성을 통해 설정된 사용자 지정 컨트롤 템플릿이 있습니다. 시각적 속성은 올바르게 설정되고 텍스트 상자에 입력하는 것조차도 작동하지만 사용자를 위해 편집을 어렵게 만드는 삽입 커서 (| 기호)는 표시되지 않습니다.사용자 정의 컨트롤 템플릿이있는 TextBox에 텍스트 커서가 표시되지 않는 이유는 무엇입니까?
전통적인 TextBox 동작을 다시 얻으려면 컨트롤 템플릿을 어떻게 변경해야합니까?
<Style x:Key="DemandEditStyle" TargetType="TextBox">
<EventSetter Event="LostFocus" Handler="DemandLostFocus" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="1" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="1" />
</Grid.RowDefinitions>
<Grid.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="White" Offset="0" />
<GradientStop Color="White" Offset="0.15" />
<GradientStop Color="#EEE" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Border Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Background="Black" />
<Border Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Background="Black" />
<Grid Grid.Row="0" Grid.Column="0" Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="1" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1" />
<RowDefinition Height="*" />
<RowDefinition Height="1" />
</Grid.RowDefinitions>
<Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Background="Black" />
<Border Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" Background="Black" />
<Border Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Background="#CCC" />
<Border Grid.Row="0" Grid.Column="2" Grid.RowSpan="3" Background="#CCC" />
<TextBlock Grid.Row="1" Grid.Column="1"
TextAlignment="Right" HorizontalAlignment="Center" VerticalAlignment="Center"
Padding="3 0 3 0" Background="Yellow"
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text}"
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualWidth}" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
업데이트하십시오에서 ScrollViewer와 함께 가장 안쪽 텍스트 상자를 교체하고 실제로 PART_ContentHost 이름는 텍스트 삽입 커서를 보여줍니다.
이 속임수를 썼는지 : 가장 안쪽 요소는 제안으로의 ScrollViewer 할 필요가있다. Thx! –
하지만 지금은 TextBox의 텍스트가 왼쪽 정렬되지 않고 오른쪽 정렬되어야 함을 나타내는 위치를 찾지 못하는 것 같습니다. ScrollViewer와 Style 모두 HorizontalContentAlignment를 Right로 설정하려고했지만 아무 소용이 없습니다. 제안 사항? –
기본 템플릿은 특별한 정렬 바인딩을 포함하고 있지 않으므로 스타일의 'Setter'에'HorizontalContentAlignment' 만 설정 했으므로'Setter'를'Style'에 추가하는 것으로 충분합니다. 'HorizontalContentAlignment'를'Right'로 설정했지만 분명히 이미 시도했습니다. 귀하의'ScrollViewer'는 사용 가능한 공간을 모두 차지합니까, 아니면 왼쪽 정렬 자체일까요? 그러면 텍스트가 왼쪽 정렬로 보이게 할 것입니다. – gehho