我的 XAML 中有以下内容:
<DataTemplate x:Key="ValueParserTemplate">
<v:EditableTextBlock x:Name ="scalarEditorTextBox" Margin="17,3,0,0" Width="134" Height="29"
FontFamily="Microsoft Sans Serif" FontSize="13"
Visibility="{Binding IsValueEditorVisible,Converter={StaticResource BoolToVisibility}}"
Text="{Binding Path=DisplayValue, UpdateSourceTrigger=Explicit, Mode=TwoWay,
ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
Focusable="True"
TextAlignment="{Binding PxValueDefinition,Converter={StaticResource aignmentConverter}}"
ReadOnly="{Binding IsOutput, RelativeSource={RelativeSource AncestorType={x:Type vo:OutputTreeView}}}"
ScalarDataType="{Binding Path=PxValueDefinition}"
TextBlockBackgroundColor="{StaticResource ScalarBackground}"
TextBoxBackgroundColor="{StaticResource ScalarBackground}"
Background="{StaticResource ScalarBackground}"
BorderBrush ="Black" BorderThickness="1,1,1,1"/>
</DataTemplate>
我想为 TextBlock 的文本进行内部填充。我尝试添加:
padding="5,5,5,5" -> no success
padding="50" -> no success
没有任何效果。看:
你知道我怎样才能得到我想要的吗?
谢谢你。
编辑:啊……我想我必须在 EditableTextBlock 中添加填充!可编辑文本块 XAML:
<Style TargetType="{x:Type v:EditableTextBlock}">
<Setter Property="MinWidth" Value="134"/>
<Setter Property="MinHeight" Value="16"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type v:EditableTextBlock}">
<Border Name="Border" BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType={x:Type v:EditableTextBlock}}}" BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource AncestorType={x:Type v:EditableTextBlock}}}" SnapsToDevicePixels="True">
<Grid x:Name="PART_GridContainer" Background="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<TextBlock x:Name="PART_TbDisplayText" Visibility="Visible"
Background="{Binding TextBlockBackgroundColor, RelativeSource={RelativeSource AncestorType={x:Type v:EditableTextBlock}}}"
Foreground="{Binding TextBlockForegroundColor, RelativeSource={RelativeSource AncestorType={x:Type v:EditableTextBlock}}}"
Text="{Binding Text, RelativeSource={RelativeSource AncestorType={x:Type v:EditableTextBlock}}, Mode=TwoWay}"
VerticalAlignment="Center" Padding="0,0,3,0"/>
<TextBox x:Name="PART_TbEditText"
Visibility="Hidden"
Background="{Binding TextBoxBackgroundColor, RelativeSource={RelativeSource AncestorType={x:Type v:EditableTextBlock}}}"
Foreground="{Binding TextBoxForegroundColor, RelativeSource={RelativeSource AncestorType={x:Type v:EditableTextBlock}}}"
Text="{Binding Text, RelativeSource={RelativeSource AncestorType={x:Type v:EditableTextBlock}}, Mode=TwoWay}"
BorderThickness="0" VerticalAlignment="Center"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Border" Property="Background" Value="LightGray"/>
<Setter TargetName="Border" Property="BorderBrush" Value="Black"/>
<Setter Property="Foreground" Value="Gray"/>
</Trigger>
<Trigger Property="Validation.HasError" Value="true">
<Setter TargetName="Border" Property="BorderBrush"
Value="Red"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="ShowFocusVisual" Value="True"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=(Validation.Errors).CurrentItem.ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>