Skip to content

Instantly share code, notes, and snippets.

@ekwus
Created September 10, 2013 09:05
Show Gist options
  • Save ekwus/6506845 to your computer and use it in GitHub Desktop.
Save ekwus/6506845 to your computer and use it in GitHub Desktop.
Example of binding MahApps.Metro Flyout IsOpen using MVVM Light
using System;
using System.Collections.ObjectModel;
using System.Threading;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using TrinityToolkit;
using TrinityPlayer.Model;
using Microsoft.Practices.ServiceLocation;
namespace TrinityPlayer.ViewModel
{
/// <summary>
/// This class contains properties that the main View can data bind to.
/// <para>
/// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
/// </para>
/// <para>
/// You can also use Blend to data bind with the tool's support.
/// </para>
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>
public class MainViewModel : ViewModelBase
{
#region Private Members
private bool mIsSettingsOpen = false;
#endregion
#region Public Properties
public AccordianViewModel Accordian
{
get
{
return ServiceLocator.Current.GetInstance<AccordianViewModel>();
}
}
public DisplayGridViewModel DisplayGrid
{
get
{
return ServiceLocator.Current.GetInstance<DisplayGridViewModel>();
}
}
public SettingsViewModel Settings
{
get
{
return ServiceLocator.Current.GetInstance<SettingsViewModel>();
}
}
public bool IsSettingsOpen
{
get { return mIsSettingsOpen; }
set
{
mIsSettingsOpen = value;
RaisePropertyChanged("IsSettingsOpen");
}
}
public RelayCommand OpenSettings { get; set; }
#endregion Public Properties
#region Constructor
public MainViewModel()
{
OpenSettings = new RelayCommand(() =>
{
IsSettingsOpen = true;
});
}
#endregion
}
}
<Controls:MetroWindow x:Class="TrinityPlayer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:v="clr-namespace:TrinityPlayer.Views"
Title="MainWindow" Height="500" Width="700"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Controls:MetroWindow.WindowCommands>
<Controls:WindowCommands>
<Button Content="settings" Command="{Binding OpenSettings}"/>
</Controls:WindowCommands>
</Controls:MetroWindow.WindowCommands>
<Controls:MetroWindow.Flyouts>
<Controls:Flyout Header="settings" Position="Right" IsOpen="{Binding IsSettingsOpen}">
<Grid>
<ContentControl Content="{Binding Settings}" />
</Grid>
</Controls:Flyout>
</Controls:MetroWindow.Flyouts>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="500*"/>
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0" Content="{Binding Accordian}"/>
<ContentControl Grid.Column="1" Content="{Binding DisplayGrid}"/>
</Grid>
</Controls:MetroWindow>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment