locked
Using a Timer to increment a value in sketchflow RRS feed

  • Question

  • Hi, 

      I am very new to sketchflow and I would like to increment a label with a timer so that it increases by 1 every second,

    thus far i have added the Change Property action to a button and added a timer, i then specified the label i wanted to increment but not sure where to go from here :\

    any help would be much appreciated :)

    Friday, November 2, 2012 5:26 PM

All replies

  • I think I would use a datastore. You could use a TimerTrigger + SetDataStoreValueAction to increment the value, then your label could be databound to the datastore.

    Steps to do this:

    1. Create a TextBlock (or label in WPF if you want)
    2. Drag a SetDataStoreValueAction from the asset panel onto LayoutRoot 
    3. Select the new action
    4. In the Properties pane, change the trigger type to TimerTrigger by pressing new
    5. It should default to 1000ms and infinite
    6. In the Common Properties section, select Property, create a new one named whatever you want, I used "LabelValue"
    7. Set the Value to 1, click the arrow to see the additional properties, click Increment, that will make it increment the value by 1 every time the timer fires
    8. Select your TextBlock, find Text in the properties pane, click the box next to it, select Data Binding,
    9. Select DataStore, DataStore, your property (I used LabelValue)
    10. Run!

    Here is what the XAML could look like in a SL SketchFlow project (should be the same/very similar for WPF):

    <UserControl
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    	xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    	mc:Ignorable="d"
    	x:Class="SilverlightPrototype2Screens.Screen_1"
    	Width="640" Height="480">
    	<UserControl.Resources>
    		<ResourceDictionary>
    			<ResourceDictionary.MergedDictionaries>
    				<ResourceDictionary Source="ProjectDataSources.xaml"/>
    			</ResourceDictionary.MergedDictionaries>
    		</ResourceDictionary>
    	</UserControl.Resources>
    
    	<Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource DataStore}}">
    		<i:Interaction.Triggers>
    			<ei:TimerTrigger>
    				<ei:SetDataStoreValueAction PropertyName="LabelValue" TargetObject="{Binding Mode=OneWay, Source={StaticResource DataStore}}" Increment="True" Value="1"/>
    			</ei:TimerTrigger>
    		</i:Interaction.Triggers>
    		<TextBlock HorizontalAlignment="Left" Height="75" Margin="46,66,0,0" Style="{StaticResource BasicTextBlock-Sketch}" TextWrapping="Wrap" Text="{Binding LabelValue}" VerticalAlignment="Top" Width="200"/>
    	</Grid>
    </UserControl>

    Friday, November 2, 2012 8:25 PM
    Moderator
  • Hi thanks very much i have it incrementing now :D however because its in the string format it jus adds one to the word "Value" every second :/

    do you know how to change the word to a number 0 and convert the textblock to a integer so that it count 1 then 2then 3and so on?

    thanks in advanced :)

    Saturday, November 3, 2012 4:01 PM
  • Whoops, missed a step :)

    In the data pane, find the edit button for your data store, change the type to number from string.

    Saturday, November 3, 2012 7:47 PM
    Moderator