What is the easiest way to put checkbox content (text) on the left side of the checkbox itself?
A solution that maximizes "easiness" and "correctness" is to make a RightToLeft
checkbox with LeftToRight
content:
<CheckBox FlowDirection="RightToLeft"> <TextBlock FlowDirection="LeftToRight" Text="CheckBox Content:" /> </CheckBox>
Or if you'd like a style:
<Style TargetType="CheckBox"> <Setter Property="FlowDirection" Value="RightToLeft" /> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <ContentControl FlowDirection="LeftToRight" Content="{Binding}" /> </DataTemplate> </Setter.Value> </Setter> </Style>
In code:
System.Windows.Controls.CheckBox checkBox = new System.Windows.Controls.CheckBox(); checkBox.Content = ":CheckBox Enabled"; checkBox.FlowDirection = System.Windows.FlowDirection.RightToLeft;
In XAML:
<CheckBox FlowDirection="RightToLeft" Content=":CheckBox Enabled" />
EDIT
User punker76 helped me notice that colon ":" has to be places infront of the text to be displayed correctly, at the end ("CheckBox Enabled:"), probably caused by an affect flow direction has on text element. Nice catch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With