Tuesday, January 29, 2013

Add a tooltip to a textbox in a grid in silverlight

Add a tooltip to a textbox in a grid in silverlight

<Grid> <Canvas>  <TextBox Name="txt" IsReadOnly="True" Width="620" VerticalAlignment="Center" Canvas.Left="340" Canvas.Top="5" Text="{Binding RowTitle2,Mode=OneWay}"     ToolTipService.ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}" TextWrapping="NoWrap" HorizontalAlignment="Stretch"/>  </Canvas> </Grid> 

this way there is no tooltip, so how to add one ? here i create dynamically records(txtboxes in the grid)

but on a similar example everything works just fine(no dynamilcall creation of txtboxes)

<Grid> <Canvas>    <TextBox Name="txt" Margin="0,5,5,0" IsReadOnly="True" Width="620" VerticalAlignment="Center"   Canvas.Left="-200" Canvas.Top="-5"  ToolTipService.ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}" TextWrapping="NoWrap" HorizontalAlignment="Stretch"/>  </Canvas> </Grid> 

Answers & Comments...

Answer: 1

What's the point here ? Its a bit confusing to use ReadOnly text box in a canvas which is located in a grid. Instead use a TextBlock which also improves performance, prevents memory leak, and looks better.

    <Grid>   <TextBlock Margin="0,5,5,0"  VerticalAlignment="Center"  HorizontalAlignment="Stretch" TextWrapping="NoWrap" Text="{Binding RowTitle2}" ToolTipService.ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}"  /> </Grid> 
by : serifcetinerhttp://stackoverflow.com/users/1530871




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog