Note that there are some explanatory texts on larger screens.

plurals
  1. POSilverlight & WPF: VisualStateManager in ControlTemplate does not work
    text
    copied!<p>So, hello everybody.</p> <p>I've made two test programs for creating a own control. One in Silverlight, one in WPF. I created a kind of RangeSlider. This Slider has of course two Orientations, Horizontal and Vertical. First I used two different techniques to create my RangeSlider. In WPF I used Triggers, in Silverlight (u know there arent Triggers) I changed the Visibility of the Horizontal and Vertical Template in CodeBehind.This runs.</p> <p>Now: I'm trying to use one technique for both, Silverlight and WPF. Therefore I use VisualStateManager.</p> <p>I've a Template defining two Sliders (one for left value, the other for right value). Simplified on the important values it looks like that:</p> <pre><code>... &lt;ControlTemplate&gt; &lt;Grid x:Name="PART_Content"&gt; &lt;!-- VSM: See following code sequence --&gt; &lt;Grid x:Name="PART_HorizontalTemplate"&gt; &lt;Slider x:Name="PART_HorizontalSliderLeft" Template="{StaticResource HorizontalSliderTemplate}" Orientation="{TemplateBinding Orientation}" /&gt; ... &lt;/Grid&gt; &lt;Grid x:Name="PART_VerticalTemplate"&gt; ... &lt;/Grid&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; </code></pre> <p>Additionally there is the VSM to switch between Horizontal and Vertical look:</p> <pre><code>&lt;VisualStateManager.VisualStateGroups&gt; &lt;VisualStateGroup&gt; &lt;VisualState x:Name="Vertical"&gt; &lt;Storyboard&gt; &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HorizontalTemplate" Storyboard.TargetProperty="Visibility"&gt; &lt;DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0"/&gt; &lt;/ObjectAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/VisualState&gt; &lt;VisualState x:Name="Horizontal" /&gt; &lt;/VisualStateGroup&gt; &lt;/VisualStateManager.VisualStateGroups&gt; </code></pre> <p>This still runs.</p> <p>As you see in the code sequence, the visual of Slider is defined by a Template, here HorizontalSliderTemplate (I reduce code again):</p> <pre><code>&lt;ControlTemplate x:Key="HorizontalSliderTemplate" TargetType="{x:Type Slider}"&gt; &lt;Border x:Name="Border" ...&gt; &lt;!-- VSM here. Like above. --&gt; &lt;Grid x:Name="Grid"&gt; &lt;Rectangle x:Name="PART_SelectionRange"/&gt; &lt;Track x:Name="PART_Track"&gt; ... &lt;/Track&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; </code></pre> <p>Actually there is also a VerticalSliderTemplate. But I want to combine both ControlTemplate in one Template and use VSM. Here we come to my problem:</p> <p>I do not get running the VSM in the 'inner' ControlTemplate. It's nearly the same code as the running VSM-Part, just the TargetName is changed. I do not know how to debug what's running on GoToState, but I believe the VSM in the template is never found and from there never execute.</p> <p>I can imagine that there's just a little detail missing, but I 'cant see the wood for the trees'. Maybe there is an important thing what I do not know about Templates or about VSM, and I'm off the track. Or do I have to trigger the 'inner' VSM from outside, or there's a possibility to access onto Elements from 'outside VSM'? Or is there no access on VSM in 'inner' Templates?</p> <p>I hope I could explain my problem good enough and there is someone, who knows a solution or maybe a keyword what I can look for. Just entering keywords VSM, ControlTemplate, Storyboard, etc. in google gives no helping hand.</p> <p>Thanks in advance.</p>
 

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