Wangshiyou
Topic Author
Posts: 9
Joined: 07 Mar 2018, 02:21

Trigger And ViewModel in c++

09 Apr 2018, 03:25

Hi,
I have a property, I want to send a notify event to my view model as soon as this property changed event occur,but I can not get my view model instance at all ,does there any suggestions
 
Wangshiyou
Topic Author
Posts: 9
Joined: 07 Mar 2018, 02:21

Re: Trigger And ViewModel in c++

09 Apr 2018, 09:09

<Style x:Key="QuestListItemStyle" TargetType="{x:Type ListBoxItem}">
  <Style.Triggers>
    <Trigger Property="IsSelected" Value="True">
      <Setter Property="local:ElementExtensions.SelectOnHover" Value="True"/>
      <Setter Property="local:ElementExtensions.FocusOnHover" Value="True"/>
    </Trigger>
  </Style.Triggers>
</Style>
for example when the quest changed i want to notify my view model that there is something changed.
 
User avatar
sfernandez
Site Admin
Posts: 1935
Joined: 22 Dec 2011, 19:20

Re: Trigger And ViewModel in c++

10 Apr 2018, 23:16

You have some options depending on how you prefer to receive the notifications.

For example, you can have in the ViewModel attached to the ListBox a property bound to the SelectedItem:
<ListBox ItemsSource="{Binding Quests}" SelectedItem="{Binding SelectedQuest}"/>
In the setter of the SelectedQuest property you can react to any change.

Or you can expose in the quest item model a Selected property and bind it to the ListBoxItem.IsSelected in the style:
<Style x:Key="QuestListItemStyle" TargetType="{x:Type ListBoxItem}">
  <Setter Property="IsSelected" Value="{Binding Selected}"/>
  ...
</Style>
The same here, in the setter of the Selected property you can do whatever you want.

Hope this helps.

Who is online

Users browsing this forum: No registered users and 2 guests