I'm trying to build the main window of my first MVVM style application. The main window is fairly simple now... it contains a tabControl which I want to act as my MDI container (ala Josh Smith's article). I've tried multiple configurations, but can't quite seem to get my first tab to show up on application launch. Here is basically what I have so far:
Public Class Application Public Sub New() 'Declare variables Dim vwMainWindow As New viewMainWindow 'Set data context vwMainWindow.DataContext = New viewModelMainWindow 'Show Main Window vwMainWindow.show() End Sub End Class
Public Class Workspace Private _tabName As String Private _ViewModelName As String Private _ViewObject As UserControl Property tabName As String Get Return _tabName End Get Set(value As String) _tabName = value End Set End Property Property ViewModelName As String Get Return _ViewModelName End Get Set(value As String) _ViewModelName = value End Set End Property Property ViewObject As UserControl Get Return _ViewObject End Get Set(value As UserControl) _ViewObject = value End Set End Property End Class
Imports System.Collections.ObjectModel Public Class viewModelMainWindow Private _Workspaces As ObservableCollection(Of Workspace) Public Sub New() 'Declare Variables Dim wsTimeClock As New Workspace Dim vwTimeClock As New viewTimeClock Dim collWorkspaces As New ObservableCollection(Of Workspace) 'Set Values for wsTimeClock wsTimeClock.ViewModelName = "vmTimeClock" wsTimeClock.tabName = "Test" wsTimeClock.ViewObject = vwTimeClock 'Add workspace to collection collWorkspaces.Add(wsTimeClock) 'Set Public Property Workspaces to collWorkspaces Me.Workspaces = collWorkspaces End Sub Public Property WorkSpaces As ObservableCollection(Of Workspace) Get Return _Workspaces End Get Set(value As ObservableCollection(Of Workspace)) value = _Workspaces End Set End Property End Class
<Window x:Class="viewMainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:WpfApplication1" Height="549" Width="615"><Grid RenderTransformOrigin="0.554,0.528"><Grid.RowDefinitions><RowDefinition Height="71*"/><RowDefinition Height="448*"/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="167"/><ColumnDefinition Width="440"/><ColumnDefinition Width="Auto"/></Grid.ColumnDefinitions><Menu HorizontalAlignment="Left" Height="28" VerticalAlignment="Top" Width="607" Grid.ColumnSpan="2" Margin="0,42,0,0"><MenuItem Header="File" Height="28"><MenuItem Header="Exit"/></MenuItem></Menu><Label Content="Test App" HorizontalAlignment="Left" Height="37" Margin="2,0,0,0" VerticalAlignment="Top" Width="605" FontSize="18.667" FontWeight="Bold" HorizontalContentAlignment="Center" Grid.ColumnSpan="2"/><TabControl ItemsSource="{Binding Path=DataContext.Workspaces}" Grid.Column="1" HorizontalAlignment="Left" Height="444" Margin="0,4,0,0" Grid.Row="1" VerticalAlignment="Top" Width="440"><TabControl.ItemTemplate><DataTemplate><TextBlock Text="{Binding Path=DataContext.Workspaces.tabName}"/></DataTemplate></TabControl.ItemTemplate></TabControl></Grid></Window>
I'm very new to this, so I feel like there's something simple I'm missing. My understanding was that, by using an Observable collection, that any controls bound to the collection would automatically refresh without the need for implementing iNotifyCollectionChanged, but maybe I'm wrong. My other thought is that I'm simply not Binding correctly in my XAML (I've probably tried 10 different variations at this point without luck).
Any help for this newbie would be greatly appreciated!!!!