0

I have having issues with a storyboard that is complaining about being unfreezable. There are alot of links on google about this, however I am not sure from reading that information how I can achieve what I want. (ie pretty much just execute a custom command from IsMouseOver property change). I am using data templating to change my listview to look like the link I have provided in the information below:

My resource dictionary:

<DataSourceProviders:ServiceLocatorProvider ServiceType="{x:Type Interfaces:IGestureBuilderModuleController}" x:Key="GestureController"/>

<Converters:IsGestureBeingBuiltConverter x:Key="IsGestureBeingBuildConverter" />

My UI looks like:

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
        <Style.Triggers>
                <MultiDataTrigger>
                      <MultiDataTrigger.Conditions>
                          <Condition Binding="{Binding IsMouseOver}" Value="True" />
                          <Condition Binding="{Binding Path=CurrentGestureState, Converter={StaticResource IsGestureBeingBuildConverter}}" Value="True" />
                      </MultiDataTrigger.Conditions>

                      <!--TODO:Need to add a button to this control. Then use the buttons event to trigger command.-->

                      <MultiDataTrigger.ExitActions>

                            <BeginStoryboard>
                              <StoryBoard:CommandTimeline StoryBoard:CommandStoryboard.Command="{Binding Source={StaticResource ResourceKey=GestureController}, Path=AddToGestureCommand}" />
                            </BeginStoryboard>
                        </MultiDataTrigger.ExitActions>
                </MultiDataTrigger>
        </Style.Triggers>
    </Style>
</ListView.ItemContainerStyle>

My converter looks like:

    [ValueConversion(typeof(GestureState), typeof(bool))]
public class IsGestureBeingBuiltConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return Equals(value, GestureState.BeingConstructed);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

My GestureState Enum looks like:

public enum GestureState
{
    Finished,
    BeingConstructed
}

My Gesture controller/command looks like:

public class GestureBuilderModuleController : ModuleController, IGestureBuilderModuleController
{
    public ICommand AddToGestureCommand
    {
        get { return new DelegateCommand<GestureBuilderViewModel>(viewModel => viewModel.AddToGesture = true); }
    }
}

My viewmodel looks like:

public GestureableItemViewModel ItemBeingAdded { get; set; }
public virtual bool AddToGesture
{
    get { return false; }
    set
    {
        if (ItemBeingAdded == null) return;
        if(CurrentGestureState != GestureState.BeingConstructed) return;

        SelectedItems.Add(ItemBeingAdded);
    }
}

The exception I am getting is:

InvalidOperation: Cannot freeze storyboard.

My UI looks LIKE this:

http://socialbarrel.com/wp-content/uploads/2011/03/Android-Like-Gesture-Unlock-Screen-Being-Tested-By-Apple-Report.jpg?98c14d

Current understanding:

I understand from reading that storyboards need to be freezable for quick access across threads where they are unfrozen.

My Question is how can I make my binding in a way that it is freezable OR achieve what I want using an alternate approach. My core problem is that I want to raise a custom command or event when mousing over a listitem when capturing a gesture.

H.B.
  • 166,899
  • 29
  • 327
  • 400
Dessus
  • 2,147
  • 1
  • 14
  • 24

1 Answers1

1

You don't need Storyboard. In your Multidatatrigger, use a OneWayToTarget DataBinding to set a property in your ViewModel. That property's setter will be invoked when the trigger condition meets. In that setter you can call "this.AddToGesture = true".

treehouse
  • 2,521
  • 1
  • 21
  • 39
  • Thanks for the reply. I have tried that but what happens then is that I must update a UI element (I want to update my viewmodel). When I update a UI elements style (with the hope of binding that back to my viewmodel) the style only lasts while the mouse is over the list item. I have read that is due to a precidence of styles as mentioned here: http://msdn.microsoft.com/en-us/library/ms743230.aspx – Dessus Jan 21 '12 at 20:12
  • Possibly I can look at this: http://geekswithblogs.net/mrnat/archive/2007/09/20/115472.aspx . Essentially use what you are suggesting in combination with an attached property, which I could attach to a ListViewItem. I could then databind that to a viewmodel and I can treat that property as IsSelected. – Dessus Jan 21 '12 at 20:27