Note that there are some explanatory texts on larger screens.

plurals
  1. POTiltEffect on TextBlock
    primarykey
    data
    text
    <p>I am using the <strong><a href="http://msdn.microsoft.com/en-us/library/ff941102%28v=vs.92%29.aspx" rel="nofollow" title="Tilt Effect overview">TiltEffect</a></strong> util provided by Microsoft. I am trying to use it with <strong>TextBlocks</strong>, however, it does not work, even if I add the TextBlock type to the list of Tiltable items:</p> <pre><code>TiltEffect.TiltableItems.Add( typeof( System.Windows.Controls.TextBlock ) ); </code></pre> <p>However, if I surround the TextBlock with a <strong>Border</strong>, and move the Tap event to the Border, it works properly.</p> <p>Is there any specific reason to this behaviour? It isn't too elegant to surround all my tappable TextBlocks with Borders.</p> <p>UPDATE: The same applies to the Rectangle shape.</p> <p>UPDATE2: My current solution is a workaround, I defined a custom control:</p> <pre><code>&lt;UserControl x:Class="MyApp.Controls.TiltableTextBlock" Name="tiltableTextBlock" ...&gt; &lt;Button Margin="0" Padding="0"&gt; &lt;Button.Template&gt; &lt;ControlTemplate&gt; &lt;TextBlock Margin="0" Padding="0" Text="{Binding Text, ElementName=tiltableTextBlock}" Style="{Binding Style, ElementName=tiltableTextBlock}" /&gt; &lt;/ControlTemplate&gt; &lt;/Button.Template&gt; &lt;/Button&gt; &lt;/UserControl&gt; </code></pre> <p>And in the code behind:</p> <pre><code>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 ) ); //NOTE: hiding the Style property of the base class, so the Style does not get applied to the UserControl, rather to the TextBlock. public new Style Style { get { return (Style)GetValue( StyleProperty ); } set { SetValue( StyleProperty, value ); } } public new static readonly DependencyProperty StyleProperty = DependencyProperty.Register( "Style", typeof( Style ), typeof( TiltableTextBlock ), new PropertyMetadata( new Style( typeof( TextBlock ) ) ) ); } </code></pre> <p>I currently do not use any other TextBlock-specific property, just Text, so if TextWrapping, FontSize, etc is needed, it has to be implemented in the same way.</p> <p>However I am not satisfied with this solution, so still looking for a more elegant workaround.</p> <p>UPDATE3: The above approach is not perfect, I found out that it nondeterministically crashes with a "parameter is incorrect" Exception (sometimes it is thrown after I start the application, sometimes not).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload