Search code examples
wpfdatagridmaterial-design-in-xaml

WPF. How to set checkbox near the textblock field?


I'm new in WPF and just want to set my checkbox field near my textblock not under it. How should I edit my xaml?

<StackPanel Grid.Row="5" Grid.Column="0" Orientation="Vertical"
                                                Margin="{StaticResource LeftTopThickness}">
                                        <TextBlock Text="{DynamicResource lang_SubscriberTreatment_Tariffs_PaperCopy}"
                                                  Visibility="{Binding Visibility, ElementName=PAPERCOPY_ID}" />
                                        <!--<TextBox x:Name="PAPERCOPY_ID" Text="{Binding PaperCopy}" />-->
                                        <CheckBox Name="PAPERCOPY_ID"  IsChecked="{Binding Path=PaperCopy,Mode=OneWay}" IsHitTestVisible="false"/>
                                    </StackPanel>

enter image description here


Solution

  • Change the Orientation of StackPanel to Horizontal instead of Vertical:

    <StackPanel Grid.Row="5" Grid.Column="0" Orientation="Horizontal" Margin="{StaticResource LeftTopThickness}">
         <TextBlock Text="{DynamicResource lang_SubscriberTreatment_Tariffs_PaperCopy}" Visibility="{Binding Visibility, ElementName=PAPERCOPY_ID}" />
         <!--<TextBox x:Name="PAPERCOPY_ID" Text="{Binding PaperCopy}" />-->
         <CheckBox Name="PAPERCOPY_ID"  IsChecked="{Binding Path=PaperCopy,Mode=OneWay}" IsHitTestVisible="false"/>
    </StackPanel>