avalondock 3.3.0.0 mvvm LayoutAnchorable
avalondock 3.3.0.0 mvvm LayoutAnchorable
我正在尝试将 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}">
当我 运行 应用程序时,我可以看到每个文档的标题,但看不到用户 controls/Views
我只得到以下信息:
如果我使用静态,则用户控件会正确显示。
搞清楚:
第一。使用任何需要保存的东西创建您的 ViewModels + 创建一个简单的 属性 标题
例如
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 或在 DockingManager 资源中创建为 DataTemplates..(下面的示例 XAML)
Observable Collection 应该是你的 object 类型,它包含你的 ViewModels 和 NOT Xceed.Wpf.AvalonDock.Layout.LayoutAnchorable
例如
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 中定义数据模板,例如
<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>
然后运行你的样本/测试你会看到你的观点..
至少这应该让您在更改其他模板或设置对接管理器样式之前启动。
我正在尝试将 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}">
当我 运行 应用程序时,我可以看到每个文档的标题,但看不到用户 controls/Views
我只得到以下信息:
如果我使用静态,则用户控件会正确显示。
搞清楚:
第一。使用任何需要保存的东西创建您的 ViewModels + 创建一个简单的 属性 标题
例如
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 或在 DockingManager 资源中创建为 DataTemplates..(下面的示例 XAML)
Observable Collection 应该是你的 object 类型,它包含你的 ViewModels 和 NOT Xceed.Wpf.AvalonDock.Layout.LayoutAnchorable
例如
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 中定义数据模板,例如
<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>
然后运行你的样本/测试你会看到你的观点..
至少这应该让您在更改其他模板或设置对接管理器样式之前启动。