I am using TiltEffect provided by Microsoft. I am trying to use it with TextBlocks , however it does not work even if I add the TextBlock type to the list of Tiltable elements:
TiltEffect.TiltableItems.Add( typeof( System.Windows.Controls.TextBlock ) );
However, if I surround the TextBlock with a Border and move the Tap event to the border, it works correctly.
Are there any specific reasons for this behavior? It's not too elegant to surround all my hidden text boxes with borders.
UPDATE: The same applies to the shape of the rectangle.
UPDATE2: My current solution is a workaround, I defined a user control:
<UserControl x:Class="MyApp.Controls.TiltableTextBlock" Name="tiltableTextBlock" ...> <Button Margin="0" Padding="0"> <Button.Template> <ControlTemplate> <TextBlock Margin="0" Padding="0" Text="{Binding Text, ElementName=tiltableTextBlock}" Style="{Binding Style, ElementName=tiltableTextBlock}" /> </ControlTemplate> </Button.Template> </Button> </UserControl>
And in the code behind:
public partial class TiltableTextBlock : UserControl { public TiltableTextBlock() { InitializeComponent(); } public string Text { get { return (string)GetValue( TextProperty ); } set { SetValue( TextProperty, value ); } } public static readonly DependencyProperty TextProperty = DependencyProperty.Register( "Text", typeof( string ), typeof( TiltableTextBlock ), new PropertyMetadata( String.Empty ) );
Currently, I am not using any other TextBlock-specific property, just Text, so if TextWrapping, FontSize, etc. is required, it should be implemented in the same way.
However, I am not satisfied with this solution, so they are still looking for a more elegant workaround.
UPDATE3: the above approach is not perfect, I found that it is non-deterministically crashing with the “wrong parameter” exception (sometimes it occurs after the application starts, sometimes not).