我正在尝试将mvvm用于avalondock 我有以下属性
Property Documents = New ObservableCollection(Of Xceed.Wpf.AvalonDock.Layout.LayoutAnchorable)
在我的ViewModel中,我有以下
Dim RemindersView As New ViewReminders ' This is a simple user control
Dim NewItem As New Xceed.Wpf.AvalonDock.Layout.LayoutAnchorable
NewItem.Title = "My Reminders"
NewItem.ContentId = "MYID123"
NewItem.Content = RemindersView
Documents.Add(NewItem)
XAML(为简单起见,我没有包含完整的xaml)
<ad:DockingManager AnchorablesSource="{Binding Documents}">
当我运行应用程序时,我可以看到每个文档的标题,但我看不到用户控件/视图
我只收到以下内容:
如果我使用静态,则会正确显示用户控件。
答案 0 :(得分:0)
弄清楚:
第一。用你需要的东西创建你的ViewModel +创建一个简单的属性Title
e.g
Public Class MyViewModel : Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Sub NF(ByVal PN As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(PN))
End Sub
Sub New()
Title = "This is My Title"
End Sub
Property RefreshCommand As New MyCommands(AddressOf RefreshCommand_)
Private Sub RefreshCommand_()
MySomeList =' Get your list from SQL/ MANUALLY OR WITH WHAT EVER IT IS THAT.
End Sub
Private _Title As String
Property Title As String
Get
Return _Title
End Get
Set(value As String)
_Title = value
NF("Title")
End Set
End Property
Private _MySomeList As IEnumerable
Property MySomeList As IEnumerable
Get
Return _MySomeList
End Get
Set(value As IEnumerable)
_MySomeList = value
NF("MySomeList")
End Set
End Property
End Class
第二。创建视图作为UserControl或作为DataTemplates在DockingManager资源中创建..(下面的示例XAML)
Observable Collection应该是你的对象的类型,它包含 ViewModels 和 NOT Xceed.Wpf.AvalonDock.Layout.LayoutAnchorable
e.g
Documents = New ObservableCollection(Of Object)
Dim DocumentsVM As New UserDashBoard.DocumentsVM
Documents.Add(DocumentsVM)
Dim CustomerBalancesVM As New UserDashBoard.CustomerBalancesViewModel
Documents.Add(CustomerBalancesVM)
Dim TransactionsVM As New UserDashBoard.TransactionsVM
Documents.Add(TransactionsVM)
Documents.Add(New UserDashBoard.RecurringTransactionVM)
然后在DockingManagerResources中定义你的dataTemplates,如
<ad:DockingManager.Resources>
<DataTemplate DataType="{x:Type profile:CustomerBalancesViewModel}">
<DataGrid AutoGenerateColumns="False" AlternatingRowBackground="White" HeadersVisibility="None" GridLinesVisibility="None" >
<DataGrid.Columns>
<DataGridTextColumn Width="*" Binding="{Binding Name}"></DataGridTextColumn>
<DataGridTextColumn Width="50" Binding="{Binding Balance}" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Right"></Setter>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</ad:DockingManager.Resources>
然后运行您的样本/测试,您将看到您的观点..
至少这应该让您在更改其他模板或设置停靠管理器样式之前启动。