I work in wpf
I use the following controls:
Button
TextBox
TextBlock
Label
TreeView
ListView
ComboBox
Is there a way to set a default border (In App.xaml) for all of them ?
Thanks,
Ilan
Wpf common border style for all controls
10.5k views Asked by user3315504 At
3
There are 3 answers
0

Thanks to all
The solution for defining Style for the border works
The only exception is the TextBox because the TextBox does not have a border in it
The solution I found for the TextBox is to define the TextBox style as follows
<Style TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<!-- Modify default template, to change triggers -->
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Ilan
I don't know other way than just setting for each type something like:
or if you already have some default style for e.g. button
This will set default
BorderThickness
andBorderBrush
for all buttons in your apps. You can also defineOnMouseOver
etc. behaviour here.For TextBlock, you will have to define template too if you want to have some border, because
TextBlock
is primitive control, withoutBorder
. If you want border you can useLabel
, which is justTextblock
with border outside.