I am using ControlTemplate to display 2 controls (below is xaml used). When I scroll down using mouse-scroll or scrollbar, and bring back that row in view, then the first textblock Displays on different row. it happens randomly. In first run, all controls display on their respective row position.
what should I do to make both textblock stick to their respective rows.
<Style x:Key="StyleDecimal2" TargetType="{x:Type igEditors:XamTextEditor}"> <Setter Property="BorderBrush" Value="LightGray"/> <Setter Property="BorderThickness" Value="0,0,1,0"/> <Setter Property="HorizontalContentAlignment" Value="Right" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igEditors:XamTextEditor}"> <DockPanel>
<!-- THIS TEXTBLOCK RANDOMLY CHANGES ROW -->
<TextBlock Text="!" x:Name="img1" Foreground="Red" FontWeight="ExtraBold" HorizontalAlignment="Left" FontSize="12" ToolTip="overriden with a value of 1." > <TextBlock.Visibility> <MultiBinding Converter="{StaticResource convMulti3}"> <Binding RelativeSource="{RelativeSource TemplatedParent}"/> </MultiBinding> </TextBlock.Visibility> </TextBlock>
<!-- THIS TEXTBLOCK ALWAYS DISPLAYS ON CORRECT ROW -->
<TextBlock HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" x:Name="TextBlock" Foreground="{TemplateBinding
DisplayText, Converter={StaticResource colorConverter}}" Text="{TemplateBinding DisplayText}"/> </DockPanel> </ControlTemplate> </Setter.Value> </Setter>
<!-- I AM NOT DOINGH EDIT, SO NO NEED TO WORRY ABOUT EDIT -->
<Setter Property="EditTemplate"> <Setter.Value> <ControlTemplate TargetType="{x:Type igEditors:XamTextEditor}"> <TextBox x:Name="PART_FocusSite"/> </ControlTemplate> </Setter.Value> </Setter> </Style>
Hello Shakti,
You can use Grid instead of StackPanel in the CellValuePresenter’s DataTemplate and set the HorizontalAlignment of TextBlocks that are inside to Right and Left. Please let me know if this helps you or you need further clarifications on this matter.
Looking forward for your reply.
Hey Stefan, How can I have the two TextBlocks alined as... one textblock to extreme left and other textblock to extreme right... looks like .. since they are in DataTemplate, they are always stick together ??
<Setter Property="ContentTemplate" > <Setter.Value> <DataTemplate> <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type ig:CellValuePresenter}},Path=Field.Width}"> <TextBlock Text="β " Foreground="Red" FontWeight="Bold" HorizontalAlignment="Left" FontStyle="Italic" > <TextBlock.Visibility> <MultiBinding Converter="{StaticResource visibilityConverter}"> <Binding RelativeSource="{RelativeSource AncestorType={x:Type ig:CellValuePresenter}}" Path="Record"/> <Binding RelativeSource="{RelativeSource AncestorType={x:Type ig:CellValuePresenter}}" Path="Field"/> <Binding RelativeSource="{RelativeSource AncestorType={x:Type ig:CellValuePresenter}}" Path="Value"/> </MultiBinding> </TextBlock.Visibility> </TextBlock> <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type ig:CellValuePresenter}},Path=Value}"/> </StackPanel> </DataTemplate> </Setter.Value> </Setter>
Thanks,
Shakti
Hey Stefan, How can I have the two TextBlocks alined as... one textblock to extreme left and another textblock to extreme right in the Column... looks like .. since they are in DataTemplate, they are always stick together ??
Thank you for your feedback. I am glad that I helped you to resolve your issue and I believe that other community members may benefit from this as well.
Thanks again.
Updated code attached.