- Wangshiyou
- Posts: 9
- Joined:
Trigger And ViewModel in c++
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
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
- Posts: 9
- Joined:
Re: Trigger And ViewModel in c++
Code: Select all
<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>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Trigger And ViewModel in c++
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:
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:
The same here, in the setter of the Selected property you can do whatever you want.
Hope this helps.
For example, you can have in the ViewModel attached to the ListBox a property bound to the SelectedItem:
Code: Select all
<ListBox ItemsSource="{Binding Quests}" SelectedItem="{Binding SelectedQuest}"/>
Or you can expose in the quest item model a Selected property and bind it to the ListBoxItem.IsSelected in the style:
Code: Select all
<Style x:Key="QuestListItemStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding Selected}"/>
...
</Style>
Hope this helps.
Who is online
Users browsing this forum: Ahrefs [Bot] and 12 guests