colin14321
Topic Author
Posts: 12
Joined: 04 Jul 2022, 20:07

EventSetter in Style

23 Aug 2022, 00:57

Hi there,

I was wondering if there is support for System.Windows.EventSetter?

I am currently trying to have an EventSetter inside of a Style. If EventSetter is not available, is there another simple way to do this inside of a style?

Code snippet:
 <TreeView.ItemContainerStyle>
                    <Style TargetType="TreeViewItem" BasedOn="{StaticResource TreeViewItem}">
                        <EventSetter Event="Loaded" Handler="TreeViewItem_Loaded"/>
                        <EventSetter Event="PreviewMouseLeftButtonDown" Handler="PointTree_MouseLeftButtonDown"/>
                        <EventSetter Event="Expanded" Handler="PointTree_Expanded"/>
                    </Style>
</TreeView.ItemContainerStyle>
                
Thank you!
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: EventSetter in Style

23 Aug 2022, 11:31

Hi,

Unfortunately EventSetter is not implemented in Noesis, it was not requested before so could you please add a ticket to our bugtracker about it?

An alternative to EventSetters is to bind to commands exposed in your viewmodel. This can be done in a style by using our StyleInteraction extension.
<TreeView.ItemContainerStyle>
  <Style TargetType="TreeViewItem" BasedOn="{StaticResource TreeViewItem}">
    <Setter Property="noesis:StyleInteraction.Triggers">
      <Setter.Value>
        <noesis:StyleTriggerCollection>
          <b:EventTrigger EventName="Loaded">
            <b:InvokeCommandAction Command="{Binding ItemLoadedCommand}"/>
          </b:EventTrigger>
          <b:EventTrigger EventName="PreviewMouseLeftButtonDown">
            <b:InvokeCommandAction Command="{Binding ItemClickedCommand}"/>
          </b:EventTrigger>
          <b:EventTrigger EventName="Expanded">
            <b:InvokeCommandAction Command="{Binding ItemExpandedCommand}"/>
          </b:EventTrigger>
        </noesis:StyleTriggerCollection>
      </Setter.Value>
    </Setter>
  </Style>
</TreeView.ItemContainerStyle>
 
colin14321
Topic Author
Posts: 12
Joined: 04 Jul 2022, 20:07

Re: EventSetter in Style

23 Aug 2022, 20:01

Yes no problem! It is under issue #2404. https://www.noesisengine.com/bugs/view.php?id=2404

I will give commands a try.

Thank you!
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: EventSetter in Style

24 Aug 2022, 11:35

Thanks for the report.

Who is online

Users browsing this forum: No registered users and 7 guests