如何將DataTemplate
的IsSelected
屬性綁定到我的視圖模型?Databind to DataTemplate.IsSelected to View Model
3
A
回答
5
我假設你DataTemplate
是提煉出來,就像ListBox
一個ItemsControl
或控制內,DataGrid
等。在這種情況下,綁定在ItemContainerStyle
例IsSelected
爲ListBox
<ListBox ItemsSource="{Binding MyCollection}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="IsSelected" Value="{Binding Selected}"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<!-- ... -->
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
+0
'Selected'在集合中的每個viewmodel上,這是我對列表框的綁定。 –
+1
然後這應該工作找到,你嘗試過嗎?每個'DataTemplate'都在'ListBoxItem'容器中,它是具有'IsSelected'屬性的容器。 'ListBoxItem'和'DataTemplate'都具有相同的'DataContext' –
相關問題
- 1. Databind to owners datacontext
- 2. WPF DataBind DataGrid to XML
- 3. convert model to viewmodel
- 4. Peewee model to JSON
- 5. json to geoDjango model
- 6. DataBind to ICollection <T>
- 7. wpf databind IsVisible to TabControl.SelectedItem!= null
- 8. select2 AJAX'd to model,configuration
- 9. Active Admin view to PDF
- 10. Laravel 5 Array to View
- 11. var javascript to asp.net MVC model
- 12. MVC Model not binding to HTTPPost action
- 13. Cakephp Containable not attached to Model
- 14. binding ng-model to ionic popover
- 15. Form :: model for one-to-one relationship
- 16. databind entityframework ObjectSet <T> to gridcontrol(c#)
- 17. Table View to DetailedView問題
- 18. Linq to SQL DeleteAllOnSubmit on View
- 19. android to long text for scrolable view
- 20. tableview to other view autoresize issue:swift
- 21. linq to SQL OnLoaded()with SQL View?
- 22. Asp.Net Master Page View Model
- 23. MVP(Model View Presenter)或MVC(Model View Controller)
- 24. GET data in django urls.py not passing to view
- 25. react-native add fragment to view is not showing
- 26. Ionic 2 ionScroll event to not refresh view
- 27. return response() - > json to Laravel View - AJAX
- 28. How to add MBProgressHUD to a queue
- 29. 如何用wicked_pdf gem如何使用html view/partial to pdf view?
- 30. Xamarin.Forms View-to-View綁定而不更改BindingContext
'的DataTemplate '沒有'IsSelected'屬性。請提供更多細節。 –