Last active
April 28, 2017 15:42
-
-
Save NewCoderNotInTown/322274bd7d2fd57bf2ae7784e1315b73 to your computer and use it in GitHub Desktop.
TwoWindowsModified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace TwoWindows | |
{ | |
public class BaseWindowViewModel | |
{ | |
public string PageTitle { get; set; } | |
public ObservableCollection<MyCustomItemViewModel> MyItems { get; } = new ObservableCollection<MyCustomItemViewModel>(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
namespace TwoWindows | |
{ | |
/// <summary> | |
/// Interaction logic for MainWindow.xaml | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
} | |
private void ClickMe_Click(object sender, RoutedEventArgs e) | |
{ | |
var windowBViewModel = new WindowBViewModel("WindowB"); | |
var windowB = new WindowB(); | |
var windowAViewModel = new WindowAViewModel("WindowA", windowBViewModel); | |
var windowA = new WindowA(); | |
windowA.DataContext = windowAViewModel; | |
windowA.Show(); | |
windowB.DataContext = windowBViewModel; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="TwoWindows.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:WB="clr-namespace:TwoWindows" | |
mc:Ignorable="d" | |
Title="MainWindow" Height="350" Width="525"> | |
<Grid> | |
<Grid.RowDefinitions> | |
<RowDefinition Height="*"/> | |
<RowDefinition Height="50"/> | |
</Grid.RowDefinitions> | |
<Button Grid.Row="1" Content="Click Me" Width="80" Height="25" Click="ClickMe_Click"/> | |
<TabControl Grid.Row="0" Margin="10"> | |
<TabItem> | |
<TabItem.Header> | |
<StackPanel> | |
<TextBlock Text="WindowB"/> | |
</StackPanel> | |
</TabItem.Header> | |
<WB:WindowB/> | |
</TabItem> | |
</TabControl> | |
</Grid> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using PropertyChanged; | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace TwoWindows | |
{ | |
[ImplementPropertyChanged] | |
public class MyCustomItemViewModel | |
{ | |
public string ItemName { get; set; } | |
public bool IsChecked { get; set; } | |
public WindowBViewModel WindowBViewModelObj { get; set; } | |
public MyCustomItemViewModel(string itemName, WindowBViewModel windowBViewModel) | |
{ | |
ItemName = itemName; | |
WindowBViewModelObj = windowBViewModel; | |
} | |
private void OnIsCheckedChanged() | |
{ | |
if (IsChecked) | |
WindowBViewModelObj.MyItems.Add(this); | |
else | |
WindowBViewModelObj.MyItems.Remove(this); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Shapes; | |
namespace TwoWindows | |
{ | |
/// <summary> | |
/// Interaction logic for WindowA.xaml | |
/// </summary> | |
public partial class WindowA : Window | |
{ | |
public WindowA() | |
{ | |
InitializeComponent(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="TwoWindows.WindowA" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:local="clr-namespace:TwoWindows" | |
mc:Ignorable="d" | |
Title="WindowA" Height="300" Width="600"> | |
<Window.Resources> | |
<CollectionViewSource x:Key='src' Source="{Binding BaseWindowViewModel}"> | |
<CollectionViewSource.SortDescriptions> | |
<scm:SortDescription PropertyName="ItemName"/> | |
</CollectionViewSource.SortDescriptions> | |
</CollectionViewSource> | |
</Window.Resources> | |
<Grid> | |
<Label Content="{Binding PageTitle}" /> | |
<ListBox ItemsSource="{Binding MyItems}"> | |
<ListBox.ItemTemplate> | |
<DataTemplate> | |
<StackPanel Orientation="Horizontal"> | |
<CheckBox Content="{Binding ItemName}" IsChecked="{Binding IsChecked}"/> | |
</StackPanel> | |
</DataTemplate> | |
</ListBox.ItemTemplate> | |
</ListBox> | |
</Grid> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace TwoWindows | |
{ | |
public class WindowAViewModel : BaseWindowViewModel | |
{ | |
//WindowBViewModel windowBViewModel is to make WindowAViewModel sees WindowBViewModel | |
public WindowAViewModel(string pageTitle, WindowBViewModel windowBViewModel) | |
{ | |
PageTitle = pageTitle; | |
MyItems.Add(new MyCustomItemViewModel("Apple", windowBViewModel)); | |
MyItems.Add(new MyCustomItemViewModel("Orange", windowBViewModel)); | |
MyItems.Add(new MyCustomItemViewModel("Banana", windowBViewModel)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Shapes; | |
namespace TwoWindows | |
{ | |
/// <summary> | |
/// Interaction logic for WindowB.xaml | |
/// </summary> | |
public partial class WindowB : UserControl | |
{ | |
public WindowB() | |
{ | |
InitializeComponent(); | |
} | |
public WindowBViewModel DataContext { get; internal set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl x:Class="TwoWindows.WindowB" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:local="clr-namespace:TwoWindows" | |
mc:Ignorable="d"> | |
<Grid> | |
<Label Content="{Binding PageTitle}" /> | |
<ListBox ItemsSource="{Binding MyItems}"> | |
<ListBox.ItemTemplate> | |
<DataTemplate> | |
<StackPanel Orientation="Horizontal"> | |
<Label Content="WindowB UserControl"/> | |
<TextBlock Text="{Binding ItemName}" /> | |
</StackPanel> | |
</DataTemplate> | |
</ListBox.ItemTemplate> | |
</ListBox> | |
</Grid> | |
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace TwoWindows | |
{ | |
public class WindowBViewModel : BaseWindowViewModel | |
{ | |
public WindowBViewModel(string pageTitle) | |
{ | |
PageTitle = pageTitle; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment