Search code examples
wpfvb.netxaml

Align content to left, checkbox to right


How can I align my checkbox to the right and the content to the left? Below is my code for the checkbox.

<StackPanel Orientation="Vertical" Grid.Row="10" Grid.ColumnSpan="2" Margin="0,0,250,0" >
  <CheckBox x:Name="chkBoxWelcomeGift" FlowDirection="RightToLeft" HorizontalAlignment="Right">
    <CheckBox.Resources>
      <Style TargetType="{x:Type Path}">
        <Setter Property="FlowDirection" Value="LeftToRight"/>
      </Style>
    </CheckBox.Resources>
  </CheckBox>
  <CheckBox x:Name="chkBoxBirthdayCoupon" FlowDirection="RightToLeft" HorizontalAlignment="Right">
    <CheckBox.Resources>
      <Style TargetType="{x:Type Path}">
        <Setter Property="FlowDirection" Value="LeftToRight"/>
      </Style>
    </CheckBox.Resources>
  </CheckBox>
  <CheckBox x:Name="chkBoxB1G1" FlowDirection="RightToLeft" HorizontalAlignment="Right">
    <CheckBox.Resources>
      <Style TargetType="{x:Type Path}">
        <Setter Property="FlowDirection" Value="LeftToRight"/>
      </Style>
    </CheckBox.Resources>
  </CheckBox>
</StackPanel>

Here is the result of the code.

result

I've try HorizontalContentAlignment="Left"> in the checkbox but it seem like didn't work. Any help will be appreciated, thanks.


Solution

  • In check box or radio button by default the content will come in right if you want it appear left, either you have to ovveride the control template and make it as you want or you can use 2 controls in combination as below

    <Wrappanel>
         <Label/>
        <Checkbox/>
    </Wrappanel>