Если у меня есть следующий XAML, определенный в generic.xaml
<Style TargetType="{x:Type TextBox}">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="CaretBrush" Value="{StaticResource TextBoxCaretBrush}" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="MinWidth" Value="120" />
<Setter Property="MinHeight" Value="20" />
<Setter Property="AllowDrop" Value="True" />
<Setter Property="Foreground" Value="{StaticResource TextBoxTextBrush}" />
<Setter Property="Padding" Value="5,3,0,5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border x:Name="Border" CornerRadius="5" Padding="2" BorderThickness="1">
<Border.Background>
<SolidColorBrush Color="{StaticResource TextBoxBackgroundColor}" />
</Border.Background>
<Border.BorderBrush>
<SolidColorBrush Color="{StaticResource TextBoxBorderColor}" />
</Border.BorderBrush>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledControlLightColor}" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="ReadOnly">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledControlDarkColor}" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="MouseOver" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ScrollViewer Margin="0" x:Name="PART_ContentHost" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" TargetName="Border" Value="{StaticResource TextBoxBorderSelectedBrush}" />
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0" Color="{StaticResource HighlightColor}" Opacity="1" BlurRadius="5" />
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="2" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
И, на мой взгляд, я определил следующий XAML для отображения TextBox с использованием вышеуказанного стиля.
<TextBox Name="UserName" attachedProperties:KeyboardNavigationExt.TabOnEnter="True" Grid.Row="1" KeyboardNavigation.TabIndex="1" Grid.Column="2" Grid.ColumnSpan="3" cal:Message.Attach="[Event TextChanged] = [Action CanLogin]" />
Это отображает TextBox в представлении с CornerRadius
из 5 на Border
в Template
.
Теперь, что касается моего вопроса, у меня есть сценарий, в котором два текстовых поля расположены рядом друг с другом, и я хотел бы указать CornerRadius
для обоих текстовых полей, как показано ниже.
<TextBox Name="UserName" CornerRadius="5,5,0,0" attachedProperties:KeyboardNavigationExt.TabOnEnter="True" Grid.Row="1" KeyboardNavigation.TabIndex="1" Grid.Column="2" Grid.ColumnSpan="3" cal:Message.Attach="[Event TextChanged] = [Action CanLogin]" />
Но TextBox не имеет CornerRadius
, как я могу добиться этого, чтобы я мог изменить CornerRadius
из Border
в представлении XAML
KeyboardNavigationExt.TabOnEnter
, но это свойство типаCornerRadius
, установите значение по умолчанию вStyle
и в шаблоне привяжитеConrnerRadius
к этому присоединенному свойствуTemplatedParent
. Таким образом, вы сможете изменить значение наTextBox
. Проверьте этот ответ - person dkozl   schedule 07.09.2015CornerRadius="{TemplateBinding CornerRadius}"
но получаю ошибку - person Neil Stevens   schedule 07.09.2015RelativeSource
кTemplatedParent
- person dkozl   schedule 07.09.2015