Page 1 of 1

Trigger And ViewModel in c++

Posted: 09 Apr 2018, 03:25
by Wangshiyou
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

Re: Trigger And ViewModel in c++

Posted: 09 Apr 2018, 09:09
by Wangshiyou
<Style x:Key="QuestListItemStyle" TargetType="{x:Type ListBoxItem}">
    <Trigger Property="IsSelected" Value="True">
      <Setter Property="local:ElementExtensions.SelectOnHover" Value="True"/>
      <Setter Property="local:ElementExtensions.FocusOnHover" Value="True"/>
for example when the quest changed i want to notify my view model that there is something changed.

Re: Trigger And ViewModel in c++

Posted: 10 Apr 2018, 23:16
by sfernandez
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}"/>
The same here, in the setter of the Selected property you can do whatever you want.

Hope this helps.