8,756
社区成员




<UserControl.Resources>
<Style>
...
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Themes:ListBoxChrome x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" SnapsToDevicePixels="true">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="0" x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<TextBlock Grid.Column="1" Margin="0,0,1,0" Text="cm" Foreground="Gray"/>
</Grid>
</Themes:ListBoxChrome>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
...
</Style>
</UserControl.Resources>
<Grid>
<TextBox Name="txt" Style="{DynamicResource TextBoxStyle1}"/>
</Grid>
public static readonly DependencyProperty UnitNameProperty = DependencyProperty.Register("UnitName", typeof(string), typeof(TextBoxWithUnit), new PropertyMetadata("cm"));
public string UnitName
{
get { return GetValue(UnitNameProperty).ToString(); }
set { SetValue(UnitNameProperty, value); }
}
public static readonly DependencyProperty UnitNameProperty = DependencyProperty.Register("UnitName", typeof(string), typeof(TextBoxWithUnit), new PropertyMetadata("", new PropertyChangedCallback(OnPropertyChanged_UnitName)));
在OnPropertyChanged_UnitName中能赋值也行