ObservableCollection with ModelView not changed



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I use the MVVM Pattern but now I have a problem with the ObservableCollection in my WorkspaceViewModel.



I want to create from a "NavigationView" a TabItem in my "WorkspaceView". This is not the problem with Commands and an EventAggregator.
Then I had the problem the TabItem lost all informations because after TabItem_Changed the ViewModel was recreated. This was fixed with an Extended TabControl. Here



ViewModel: WorkspaceViewModel



public class WorkspaceViewModel : ViewModelBase.ViewModelBase

public WorkspaceViewModel()

this.TabItems = new ObservableCollection<ViewModelBase.ViewModelBase>();
CreateTabItemEvent.Instance.Subscribe(CreateTabItem);


#region Properties

private ViewModelBase.ViewModelBase _SelectedTabItem;
public ViewModelBase.ViewModelBase SelectedTabItem

get return _SelectedTabItem;
set SetProperty(ref _SelectedTabItem, value);


private ObservableCollection<ViewModelBase.ViewModelBase> _TabItems;
public ObservableCollection<ViewModelBase.ViewModelBase> TabItems

get return _TabItems;
set SetProperty(ref _TabItems, value);


#endregion

#region Methodes

private void CreateTabItem(string pObjectName)

//create TabItem and add it to the list
ViewModelBase.ViewModelBase newTabItem = null;

//Test Objects from Buttonnames
if (pObjectName.EndsWith("1"))

newTabItem = new CustomerViewModel();

else if (pObjectName.EndsWith("2"))

newTabItem = new ContactViewModel();


if (newTabItem != null)

this.TabItems.Add(newTabItem);
this.SelectedTabItem = newTabItem;

//Test Refresh - not work because list is "old"
RaisePropertyChanged(nameof(this.TabItems));



#endregion



View: WorkspaceView



 <UserControl.Resources>
<DataTemplate DataType="x:Type viewmodel:CustomerViewModel">
<view:CustomerView/>
</DataTemplate>
<DataTemplate DataType="x:Type viewmodel:ContactViewModel">
<view:ContactView/>
</DataTemplate>

<Style TargetType="x:Type tabControlEx:TabControlEx">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type TabControl">
<Grid Background="TemplateBinding Background" ClipToBounds="True" KeyboardNavigation.TabNavigation="Local" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0" />
<ColumnDefinition x:Name="ColumnDefinition1" Width="0" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDefinition0" Height="Auto" />
<RowDefinition x:Name="RowDefinition1" Height="*" />
</Grid.RowDefinitions>
<DockPanel Margin="2,2,0,0" LastChildFill="False">
<TabPanel x:Name="HeaderPanel" Margin="0,0,0,-1" VerticalAlignment="Bottom" Panel.ZIndex="1" DockPanel.Dock="Left"
IsItemsHost="True" KeyboardNavigation.TabIndex="1" />
</DockPanel>
<Border x:Name="ContentPanel" Grid.Row="1" Grid.Column="0"
Background="TemplateBinding Background"
BorderBrush="TemplateBinding BorderBrush"
BorderThickness="TemplateBinding BorderThickness"
KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
<Grid x:Name="PART_ItemsHolder" Margin="TemplateBinding Padding" SnapsToDevicePixels="TemplateBinding SnapsToDevicePixels" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Text="Workspace Control"></TextBlock>
<tabControlEx:TabControlEx x:Name="tbWorkspace" Grid.Row="1"
ItemsSource="Binding TabItems" SelectedItem="Binding SelectedTabItem"
IsSynchronizedWithCurrentItem="True" >

<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header" Value="Binding Title"/>
</Style>
</TabControl.ItemContainerStyle>

</tabControlEx:TabControlEx>
</Grid>


ViewModel: CustomerViewModel



public class CustomerViewModel : ViewModelBase.ViewModelBase

public CustomerViewModel()

this.SendMessageCommand = new DelegateCommand<string>(SendMessage);
this.Title = "Customer";


#region Commands

private ICommand _SendMessageCommand;
public ICommand SendMessageCommand

get return _SendMessageCommand;
set SetProperty(ref _SendMessageCommand, value);


#endregion

#region Methodes

private void SendMessage(string pMessage)

//Test to change the Title on the TabItem
this.Title = pMessage;
this.EditModus = false;
MessageSentEvent.Instance.Publish(pMessage);


#endregion



Now if I click on the button which is use the Command "SendMessageCommand" the Title is changed but the TabItem Header is not changed. The Title is every time "Customer" and the EditMode = true.
After this I look at the ObservableCollection in the WorkspaceViewModel... There is no changes. It has the "Title = Customer" and "EditMode = true"



So why the changes from the CustomerViewModel not apply the the WorkspaceViewModel.ObservableCollection?



Can someone help me?



Sample Project



EDIT:



ViewModel: ViewModelBase



 public class ViewModelBase : BindableBase

public ViewModelBase()

this.Title = String.Empty;
this.EditModus = true;


#region Properties

private string _Title;
public string Title

get return _Title;
set SetProperty(ref _Title, value);


private bool _EditModus;
public bool EditModus

get return _EditModus;
set SetProperty(ref _EditModus, value);


#endregion



all ViewModels inherits from ViewModelBase and BindableBase from Prism 7 has INotifyPropertyChanged



EDIT 2: SOLUTION



I found the error. If I create a new TabItem, I create a new ViewModel too. But in the XAML I create a new ViewModel too. So the View hasnt the same ViewModel as the ObservableCollection in the WorkspaceViewModel.
So I delete the DataContext in the XAML and now it works.



<UserControl x:Class="CustomerModul.View.CustomerView"
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:CustomerModul.View"
xmlns:vm="clr-namespace:CustomerModul.ViewModel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.DataContext>
<vm:CustomerViewModel/>
</UserControl.DataContext>

<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>

<CheckBox Grid.Row="0" IsChecked="Binding EditModus">EditModus aktiv</CheckBox>
<Button Grid.Row="1" Command="Binding SendMessageCommand" CommandParameter="Gespeichert" Content="Save"></Button>
</Grid>











share|improve this question
























  • Can you please include the code for the Title property? Did you raise the OnPropertyNotifyChanged event?

    – Klaus Gütter
    Nov 15 '18 at 10:39











  • The CustomerViewModel inherits from ViewModelBase and I use the BindableBase from Prism 7. I edit my Question.

    – abbahex
    Nov 15 '18 at 10:50

















0















I use the MVVM Pattern but now I have a problem with the ObservableCollection in my WorkspaceViewModel.



I want to create from a "NavigationView" a TabItem in my "WorkspaceView". This is not the problem with Commands and an EventAggregator.
Then I had the problem the TabItem lost all informations because after TabItem_Changed the ViewModel was recreated. This was fixed with an Extended TabControl. Here



ViewModel: WorkspaceViewModel



public class WorkspaceViewModel : ViewModelBase.ViewModelBase

public WorkspaceViewModel()

this.TabItems = new ObservableCollection<ViewModelBase.ViewModelBase>();
CreateTabItemEvent.Instance.Subscribe(CreateTabItem);


#region Properties

private ViewModelBase.ViewModelBase _SelectedTabItem;
public ViewModelBase.ViewModelBase SelectedTabItem

get return _SelectedTabItem;
set SetProperty(ref _SelectedTabItem, value);


private ObservableCollection<ViewModelBase.ViewModelBase> _TabItems;
public ObservableCollection<ViewModelBase.ViewModelBase> TabItems

get return _TabItems;
set SetProperty(ref _TabItems, value);


#endregion

#region Methodes

private void CreateTabItem(string pObjectName)

//create TabItem and add it to the list
ViewModelBase.ViewModelBase newTabItem = null;

//Test Objects from Buttonnames
if (pObjectName.EndsWith("1"))

newTabItem = new CustomerViewModel();

else if (pObjectName.EndsWith("2"))

newTabItem = new ContactViewModel();


if (newTabItem != null)

this.TabItems.Add(newTabItem);
this.SelectedTabItem = newTabItem;

//Test Refresh - not work because list is "old"
RaisePropertyChanged(nameof(this.TabItems));



#endregion



View: WorkspaceView



 <UserControl.Resources>
<DataTemplate DataType="x:Type viewmodel:CustomerViewModel">
<view:CustomerView/>
</DataTemplate>
<DataTemplate DataType="x:Type viewmodel:ContactViewModel">
<view:ContactView/>
</DataTemplate>

<Style TargetType="x:Type tabControlEx:TabControlEx">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type TabControl">
<Grid Background="TemplateBinding Background" ClipToBounds="True" KeyboardNavigation.TabNavigation="Local" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0" />
<ColumnDefinition x:Name="ColumnDefinition1" Width="0" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDefinition0" Height="Auto" />
<RowDefinition x:Name="RowDefinition1" Height="*" />
</Grid.RowDefinitions>
<DockPanel Margin="2,2,0,0" LastChildFill="False">
<TabPanel x:Name="HeaderPanel" Margin="0,0,0,-1" VerticalAlignment="Bottom" Panel.ZIndex="1" DockPanel.Dock="Left"
IsItemsHost="True" KeyboardNavigation.TabIndex="1" />
</DockPanel>
<Border x:Name="ContentPanel" Grid.Row="1" Grid.Column="0"
Background="TemplateBinding Background"
BorderBrush="TemplateBinding BorderBrush"
BorderThickness="TemplateBinding BorderThickness"
KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
<Grid x:Name="PART_ItemsHolder" Margin="TemplateBinding Padding" SnapsToDevicePixels="TemplateBinding SnapsToDevicePixels" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Text="Workspace Control"></TextBlock>
<tabControlEx:TabControlEx x:Name="tbWorkspace" Grid.Row="1"
ItemsSource="Binding TabItems" SelectedItem="Binding SelectedTabItem"
IsSynchronizedWithCurrentItem="True" >

<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header" Value="Binding Title"/>
</Style>
</TabControl.ItemContainerStyle>

</tabControlEx:TabControlEx>
</Grid>


ViewModel: CustomerViewModel



public class CustomerViewModel : ViewModelBase.ViewModelBase

public CustomerViewModel()

this.SendMessageCommand = new DelegateCommand<string>(SendMessage);
this.Title = "Customer";


#region Commands

private ICommand _SendMessageCommand;
public ICommand SendMessageCommand

get return _SendMessageCommand;
set SetProperty(ref _SendMessageCommand, value);


#endregion

#region Methodes

private void SendMessage(string pMessage)

//Test to change the Title on the TabItem
this.Title = pMessage;
this.EditModus = false;
MessageSentEvent.Instance.Publish(pMessage);


#endregion



Now if I click on the button which is use the Command "SendMessageCommand" the Title is changed but the TabItem Header is not changed. The Title is every time "Customer" and the EditMode = true.
After this I look at the ObservableCollection in the WorkspaceViewModel... There is no changes. It has the "Title = Customer" and "EditMode = true"



So why the changes from the CustomerViewModel not apply the the WorkspaceViewModel.ObservableCollection?



Can someone help me?



Sample Project



EDIT:



ViewModel: ViewModelBase



 public class ViewModelBase : BindableBase

public ViewModelBase()

this.Title = String.Empty;
this.EditModus = true;


#region Properties

private string _Title;
public string Title

get return _Title;
set SetProperty(ref _Title, value);


private bool _EditModus;
public bool EditModus

get return _EditModus;
set SetProperty(ref _EditModus, value);


#endregion



all ViewModels inherits from ViewModelBase and BindableBase from Prism 7 has INotifyPropertyChanged



EDIT 2: SOLUTION



I found the error. If I create a new TabItem, I create a new ViewModel too. But in the XAML I create a new ViewModel too. So the View hasnt the same ViewModel as the ObservableCollection in the WorkspaceViewModel.
So I delete the DataContext in the XAML and now it works.



<UserControl x:Class="CustomerModul.View.CustomerView"
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:CustomerModul.View"
xmlns:vm="clr-namespace:CustomerModul.ViewModel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.DataContext>
<vm:CustomerViewModel/>
</UserControl.DataContext>

<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>

<CheckBox Grid.Row="0" IsChecked="Binding EditModus">EditModus aktiv</CheckBox>
<Button Grid.Row="1" Command="Binding SendMessageCommand" CommandParameter="Gespeichert" Content="Save"></Button>
</Grid>











share|improve this question
























  • Can you please include the code for the Title property? Did you raise the OnPropertyNotifyChanged event?

    – Klaus Gütter
    Nov 15 '18 at 10:39











  • The CustomerViewModel inherits from ViewModelBase and I use the BindableBase from Prism 7. I edit my Question.

    – abbahex
    Nov 15 '18 at 10:50













0












0








0








I use the MVVM Pattern but now I have a problem with the ObservableCollection in my WorkspaceViewModel.



I want to create from a "NavigationView" a TabItem in my "WorkspaceView". This is not the problem with Commands and an EventAggregator.
Then I had the problem the TabItem lost all informations because after TabItem_Changed the ViewModel was recreated. This was fixed with an Extended TabControl. Here



ViewModel: WorkspaceViewModel



public class WorkspaceViewModel : ViewModelBase.ViewModelBase

public WorkspaceViewModel()

this.TabItems = new ObservableCollection<ViewModelBase.ViewModelBase>();
CreateTabItemEvent.Instance.Subscribe(CreateTabItem);


#region Properties

private ViewModelBase.ViewModelBase _SelectedTabItem;
public ViewModelBase.ViewModelBase SelectedTabItem

get return _SelectedTabItem;
set SetProperty(ref _SelectedTabItem, value);


private ObservableCollection<ViewModelBase.ViewModelBase> _TabItems;
public ObservableCollection<ViewModelBase.ViewModelBase> TabItems

get return _TabItems;
set SetProperty(ref _TabItems, value);


#endregion

#region Methodes

private void CreateTabItem(string pObjectName)

//create TabItem and add it to the list
ViewModelBase.ViewModelBase newTabItem = null;

//Test Objects from Buttonnames
if (pObjectName.EndsWith("1"))

newTabItem = new CustomerViewModel();

else if (pObjectName.EndsWith("2"))

newTabItem = new ContactViewModel();


if (newTabItem != null)

this.TabItems.Add(newTabItem);
this.SelectedTabItem = newTabItem;

//Test Refresh - not work because list is "old"
RaisePropertyChanged(nameof(this.TabItems));



#endregion



View: WorkspaceView



 <UserControl.Resources>
<DataTemplate DataType="x:Type viewmodel:CustomerViewModel">
<view:CustomerView/>
</DataTemplate>
<DataTemplate DataType="x:Type viewmodel:ContactViewModel">
<view:ContactView/>
</DataTemplate>

<Style TargetType="x:Type tabControlEx:TabControlEx">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type TabControl">
<Grid Background="TemplateBinding Background" ClipToBounds="True" KeyboardNavigation.TabNavigation="Local" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0" />
<ColumnDefinition x:Name="ColumnDefinition1" Width="0" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDefinition0" Height="Auto" />
<RowDefinition x:Name="RowDefinition1" Height="*" />
</Grid.RowDefinitions>
<DockPanel Margin="2,2,0,0" LastChildFill="False">
<TabPanel x:Name="HeaderPanel" Margin="0,0,0,-1" VerticalAlignment="Bottom" Panel.ZIndex="1" DockPanel.Dock="Left"
IsItemsHost="True" KeyboardNavigation.TabIndex="1" />
</DockPanel>
<Border x:Name="ContentPanel" Grid.Row="1" Grid.Column="0"
Background="TemplateBinding Background"
BorderBrush="TemplateBinding BorderBrush"
BorderThickness="TemplateBinding BorderThickness"
KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
<Grid x:Name="PART_ItemsHolder" Margin="TemplateBinding Padding" SnapsToDevicePixels="TemplateBinding SnapsToDevicePixels" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Text="Workspace Control"></TextBlock>
<tabControlEx:TabControlEx x:Name="tbWorkspace" Grid.Row="1"
ItemsSource="Binding TabItems" SelectedItem="Binding SelectedTabItem"
IsSynchronizedWithCurrentItem="True" >

<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header" Value="Binding Title"/>
</Style>
</TabControl.ItemContainerStyle>

</tabControlEx:TabControlEx>
</Grid>


ViewModel: CustomerViewModel



public class CustomerViewModel : ViewModelBase.ViewModelBase

public CustomerViewModel()

this.SendMessageCommand = new DelegateCommand<string>(SendMessage);
this.Title = "Customer";


#region Commands

private ICommand _SendMessageCommand;
public ICommand SendMessageCommand

get return _SendMessageCommand;
set SetProperty(ref _SendMessageCommand, value);


#endregion

#region Methodes

private void SendMessage(string pMessage)

//Test to change the Title on the TabItem
this.Title = pMessage;
this.EditModus = false;
MessageSentEvent.Instance.Publish(pMessage);


#endregion



Now if I click on the button which is use the Command "SendMessageCommand" the Title is changed but the TabItem Header is not changed. The Title is every time "Customer" and the EditMode = true.
After this I look at the ObservableCollection in the WorkspaceViewModel... There is no changes. It has the "Title = Customer" and "EditMode = true"



So why the changes from the CustomerViewModel not apply the the WorkspaceViewModel.ObservableCollection?



Can someone help me?



Sample Project



EDIT:



ViewModel: ViewModelBase



 public class ViewModelBase : BindableBase

public ViewModelBase()

this.Title = String.Empty;
this.EditModus = true;


#region Properties

private string _Title;
public string Title

get return _Title;
set SetProperty(ref _Title, value);


private bool _EditModus;
public bool EditModus

get return _EditModus;
set SetProperty(ref _EditModus, value);


#endregion



all ViewModels inherits from ViewModelBase and BindableBase from Prism 7 has INotifyPropertyChanged



EDIT 2: SOLUTION



I found the error. If I create a new TabItem, I create a new ViewModel too. But in the XAML I create a new ViewModel too. So the View hasnt the same ViewModel as the ObservableCollection in the WorkspaceViewModel.
So I delete the DataContext in the XAML and now it works.



<UserControl x:Class="CustomerModul.View.CustomerView"
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:CustomerModul.View"
xmlns:vm="clr-namespace:CustomerModul.ViewModel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.DataContext>
<vm:CustomerViewModel/>
</UserControl.DataContext>

<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>

<CheckBox Grid.Row="0" IsChecked="Binding EditModus">EditModus aktiv</CheckBox>
<Button Grid.Row="1" Command="Binding SendMessageCommand" CommandParameter="Gespeichert" Content="Save"></Button>
</Grid>











share|improve this question
















I use the MVVM Pattern but now I have a problem with the ObservableCollection in my WorkspaceViewModel.



I want to create from a "NavigationView" a TabItem in my "WorkspaceView". This is not the problem with Commands and an EventAggregator.
Then I had the problem the TabItem lost all informations because after TabItem_Changed the ViewModel was recreated. This was fixed with an Extended TabControl. Here



ViewModel: WorkspaceViewModel



public class WorkspaceViewModel : ViewModelBase.ViewModelBase

public WorkspaceViewModel()

this.TabItems = new ObservableCollection<ViewModelBase.ViewModelBase>();
CreateTabItemEvent.Instance.Subscribe(CreateTabItem);


#region Properties

private ViewModelBase.ViewModelBase _SelectedTabItem;
public ViewModelBase.ViewModelBase SelectedTabItem

get return _SelectedTabItem;
set SetProperty(ref _SelectedTabItem, value);


private ObservableCollection<ViewModelBase.ViewModelBase> _TabItems;
public ObservableCollection<ViewModelBase.ViewModelBase> TabItems

get return _TabItems;
set SetProperty(ref _TabItems, value);


#endregion

#region Methodes

private void CreateTabItem(string pObjectName)

//create TabItem and add it to the list
ViewModelBase.ViewModelBase newTabItem = null;

//Test Objects from Buttonnames
if (pObjectName.EndsWith("1"))

newTabItem = new CustomerViewModel();

else if (pObjectName.EndsWith("2"))

newTabItem = new ContactViewModel();


if (newTabItem != null)

this.TabItems.Add(newTabItem);
this.SelectedTabItem = newTabItem;

//Test Refresh - not work because list is "old"
RaisePropertyChanged(nameof(this.TabItems));



#endregion



View: WorkspaceView



 <UserControl.Resources>
<DataTemplate DataType="x:Type viewmodel:CustomerViewModel">
<view:CustomerView/>
</DataTemplate>
<DataTemplate DataType="x:Type viewmodel:ContactViewModel">
<view:ContactView/>
</DataTemplate>

<Style TargetType="x:Type tabControlEx:TabControlEx">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type TabControl">
<Grid Background="TemplateBinding Background" ClipToBounds="True" KeyboardNavigation.TabNavigation="Local" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0" />
<ColumnDefinition x:Name="ColumnDefinition1" Width="0" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDefinition0" Height="Auto" />
<RowDefinition x:Name="RowDefinition1" Height="*" />
</Grid.RowDefinitions>
<DockPanel Margin="2,2,0,0" LastChildFill="False">
<TabPanel x:Name="HeaderPanel" Margin="0,0,0,-1" VerticalAlignment="Bottom" Panel.ZIndex="1" DockPanel.Dock="Left"
IsItemsHost="True" KeyboardNavigation.TabIndex="1" />
</DockPanel>
<Border x:Name="ContentPanel" Grid.Row="1" Grid.Column="0"
Background="TemplateBinding Background"
BorderBrush="TemplateBinding BorderBrush"
BorderThickness="TemplateBinding BorderThickness"
KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
<Grid x:Name="PART_ItemsHolder" Margin="TemplateBinding Padding" SnapsToDevicePixels="TemplateBinding SnapsToDevicePixels" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Text="Workspace Control"></TextBlock>
<tabControlEx:TabControlEx x:Name="tbWorkspace" Grid.Row="1"
ItemsSource="Binding TabItems" SelectedItem="Binding SelectedTabItem"
IsSynchronizedWithCurrentItem="True" >

<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header" Value="Binding Title"/>
</Style>
</TabControl.ItemContainerStyle>

</tabControlEx:TabControlEx>
</Grid>


ViewModel: CustomerViewModel



public class CustomerViewModel : ViewModelBase.ViewModelBase

public CustomerViewModel()

this.SendMessageCommand = new DelegateCommand<string>(SendMessage);
this.Title = "Customer";


#region Commands

private ICommand _SendMessageCommand;
public ICommand SendMessageCommand

get return _SendMessageCommand;
set SetProperty(ref _SendMessageCommand, value);


#endregion

#region Methodes

private void SendMessage(string pMessage)

//Test to change the Title on the TabItem
this.Title = pMessage;
this.EditModus = false;
MessageSentEvent.Instance.Publish(pMessage);


#endregion



Now if I click on the button which is use the Command "SendMessageCommand" the Title is changed but the TabItem Header is not changed. The Title is every time "Customer" and the EditMode = true.
After this I look at the ObservableCollection in the WorkspaceViewModel... There is no changes. It has the "Title = Customer" and "EditMode = true"



So why the changes from the CustomerViewModel not apply the the WorkspaceViewModel.ObservableCollection?



Can someone help me?



Sample Project



EDIT:



ViewModel: ViewModelBase



 public class ViewModelBase : BindableBase

public ViewModelBase()

this.Title = String.Empty;
this.EditModus = true;


#region Properties

private string _Title;
public string Title

get return _Title;
set SetProperty(ref _Title, value);


private bool _EditModus;
public bool EditModus

get return _EditModus;
set SetProperty(ref _EditModus, value);


#endregion



all ViewModels inherits from ViewModelBase and BindableBase from Prism 7 has INotifyPropertyChanged



EDIT 2: SOLUTION



I found the error. If I create a new TabItem, I create a new ViewModel too. But in the XAML I create a new ViewModel too. So the View hasnt the same ViewModel as the ObservableCollection in the WorkspaceViewModel.
So I delete the DataContext in the XAML and now it works.



<UserControl x:Class="CustomerModul.View.CustomerView"
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:CustomerModul.View"
xmlns:vm="clr-namespace:CustomerModul.ViewModel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.DataContext>
<vm:CustomerViewModel/>
</UserControl.DataContext>

<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>

<CheckBox Grid.Row="0" IsChecked="Binding EditModus">EditModus aktiv</CheckBox>
<Button Grid.Row="1" Command="Binding SendMessageCommand" CommandParameter="Gespeichert" Content="Save"></Button>
</Grid>








c# wpf mvvm prism observablecollection






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 14:39







abbahex

















asked Nov 15 '18 at 10:09









abbahexabbahex

83




83












  • Can you please include the code for the Title property? Did you raise the OnPropertyNotifyChanged event?

    – Klaus Gütter
    Nov 15 '18 at 10:39











  • The CustomerViewModel inherits from ViewModelBase and I use the BindableBase from Prism 7. I edit my Question.

    – abbahex
    Nov 15 '18 at 10:50

















  • Can you please include the code for the Title property? Did you raise the OnPropertyNotifyChanged event?

    – Klaus Gütter
    Nov 15 '18 at 10:39











  • The CustomerViewModel inherits from ViewModelBase and I use the BindableBase from Prism 7. I edit my Question.

    – abbahex
    Nov 15 '18 at 10:50
















Can you please include the code for the Title property? Did you raise the OnPropertyNotifyChanged event?

– Klaus Gütter
Nov 15 '18 at 10:39





Can you please include the code for the Title property? Did you raise the OnPropertyNotifyChanged event?

– Klaus Gütter
Nov 15 '18 at 10:39













The CustomerViewModel inherits from ViewModelBase and I use the BindableBase from Prism 7. I edit my Question.

– abbahex
Nov 15 '18 at 10:50





The CustomerViewModel inherits from ViewModelBase and I use the BindableBase from Prism 7. I edit my Question.

– abbahex
Nov 15 '18 at 10:50












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53316996%2fobservablecollection-with-modelview-not-changed%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53316996%2fobservablecollection-with-modelview-not-changed%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo