Created
April 10, 2014 17:56
-
-
Save julesx/10406971 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Collections.ObjectModel; | |
using System.ComponentModel; | |
using WpfApplication14.Annotations; | |
namespace WpfApplication14 | |
{ | |
public class MainVm : INotifyPropertyChanged | |
{ | |
#region Singleton Setup | |
private static readonly MainVm Instance = new MainVm(); | |
public static MainVm Current | |
{ | |
get { return Instance; } | |
} | |
#endregion | |
#region GUI Vars | |
public ObservableCollection<MenuVm> MenuVms { get; set; } | |
private MainVm _activeVm; | |
public MainVm ActiveVm | |
{ | |
get { return _activeVm; } | |
set | |
{ | |
_activeVm = value; | |
OnPropertyChanged("ActiveVm"); | |
} | |
} | |
#endregion | |
#region C'Tor | |
public MainVm() | |
{ | |
MenuVms = new ObservableCollection<MenuVm>(); | |
MenuVms.Add(new MenuVm()); | |
MenuVms.Add(new MenuVm()); | |
MenuVms.Add(new MenuVm()); | |
MenuVms.Add(new MenuVm()); | |
MenuVms.Add(new MenuVm()); | |
} | |
#endregion | |
public event PropertyChangedEventHandler PropertyChanged; | |
[NotifyPropertyChangedInvocator] | |
protected virtual void OnPropertyChanged(string propertyName) | |
{ | |
PropertyChangedEventHandler handler = PropertyChanged; | |
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} | |
} |
This file contains hidden or 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
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
MainVm.Current.ActiveVm = MainVm.Current; // DOESNT WORK | |
//DataContext = MainVm.Current; // WORKS | |
} | |
} |
This file contains hidden or 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="WpfApplication14.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
Title="MainWindow" Height="350" Width="525"> | |
<Grid> | |
<Grid.Resources> | |
<CollectionViewSource x:Key="MenuVms" Source="{Binding MenuVms}" /> | |
</Grid.Resources> | |
<Button DataContext="{Binding ActiveVm}" Width="25" Height="25" Name="OptionsButton"> | |
<Button.ContextMenu> | |
<ContextMenu Placement="Top"> | |
<ContextMenu.ItemsSource> | |
<CompositeCollection> | |
<CollectionContainer Collection="{Binding Source={StaticResource MenuVms}}" /> | |
</CompositeCollection> | |
</ContextMenu.ItemsSource> | |
</ContextMenu> | |
</Button.ContextMenu> | |
<!--<Button.Template> | |
<ControlTemplate>--> | |
<Rectangle Width="25" Height="25" Fill="Pink" /> | |
<!--</ControlTemplate> | |
</Button.Template>--> | |
</Button> | |
</Grid> | |
</Window> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment