Skip to content

Instantly share code, notes, and snippets.

@jmreynolds
Last active December 11, 2015 12:29
Show Gist options
  • Save jmreynolds/4601281 to your computer and use it in GitHub Desktop.
Save jmreynolds/4601281 to your computer and use it in GitHub Desktop.
Method used to set the action collection in a parent view from a Partial View
private void SetParentActions()
{
Actions.Add(new CloseCurrentViewAction(this, beginGroup: true));
Parent.ChildViewActions.Clear();
Parent.ChildViewActions.Add(AddSideToCartAction);
Parent.Actions.Clear();
foreach (IViewAction childViewAction in Parent.ChildViewActions)
Parent.Actions.Add(childViewAction);
Parent.Actions.Add(new CloseCurrentViewAction(Parent, beginGroup: true));
}
<Style TargetType="ItemsControl" x:Key="CODE.Framework-Layout-PrimarySecondaryFormLayout-Vertical-Split">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Layout:GridPrimarySecondary UIElementSpacing="5"
SecondaryAreaBackgroundBrush="{DynamicResource CODE.Framework-Application-ThemeBrush1}"
SecondaryAreaBackgroundBrushOpacity=".9"
SecondaryUIElementMargin="10"
PrimaryAreaBackgroundBrush="{DynamicResource CODE.Framework-Application-ThemeBrush1}"
PrimaryAreaBackgroundBrushOpacity=".9"
PrimaryUIElementMargin="10"
SecondaryUIElementAlignmentChangeSize ="1"
/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="{x:Null}" />
</Style>
<mvvm:View xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:mvvm="clr-namespace:CODE.Framework.Wpf.Mvvm;assembly=CODE.Framework.Wpf.Mvvm"
Title="Review"
Style="{DynamicResource CODE.Framework-Layout-PrimarySecondaryFormLayout-Vertical-Split}"
>
<mvvm:PartialView Controller="ReviewController"
Action="{Binding MainReviewScreen}"
Width="auto" Height="auto" />
<mvvm:View UIElementType="Secondary">
<StackPanel>
<Button Command="{Binding ReviewPizzasAction}"
Content="{Binding ReviewPizzasAction.Caption}"></Button>
<Button Command="{Binding ReviewSidesAction}"
Content="{Binding ReviewSidesAction.Caption}"></Button>
</StackPanel>
</mvvm:View>
</mvvm:View>
private string _mainReviewScreen;
public string MainReviewScreen
{
get { return _mainReviewScreen; }
set
{
if (value == _mainReviewScreen) return;
_mainReviewScreen = value;
NotifyChanged("MainReviewScreen");
}
}
public ActionResult Sides()
{
var model = new ReviewSidesViewModel();
return PartialView(model);
}
<mvvm:View xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:mvvm="clr-namespace:CODE.Framework.Wpf.Mvvm;assembly=CODE.Framework.Wpf.Mvvm"
xmlns:Controls="clr-namespace:CODE.Framework.Wpf.Controls;assembly=CODE.Framework.Wpf"
Title="New View"
Style="{DynamicResource CODE.Framework-Layout-PrimarySecondaryFormLayout}"
>
<ListBox ItemsSource="{Binding Pizzas}" mvvm:View.UIElementType="Primary"
SelectedItem="{Binding SelectedPizza}" Controls:ListBoxEx.Command="{Binding AddPizzaToCartAction}"
Controls:ListBoxEx.CommandTrigger="DoubleClick" Style="{DynamicResource PizzaList}" >
</ListBox>
<mvvm:View UIElementType="Secondary" Style="{DynamicResource CODE.Framework-Layout-SimpleFormLayout}">
<Label>Search Class Name:</Label>
<TextBox Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" mvvm:View.HasDefaultFocus="True">
<TextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding SearchAction}" />
</TextBox.InputBindings>
</TextBox>
<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
<Button HorizontalAlignment="Right" Content="{Binding ClearFilterAction.Caption}"
Command="{Binding ClearFilterAction}" />
<Button Margin="5,0,0,0" HorizontalAlignment="Right" Content="{Binding SearchAction.Caption}"
Command="{Binding SearchAction}" />
</StackPanel>
</mvvm:View>
</mvvm:View>
using CODE.Framework.Wpf.Mvvm;
namespace AddActionsToParentViewModel.Client.Wpf.Models.Review
{
public class ReviewViewModel : ViewModelBase
{
private ReviewViewModel()
{
ReviewPizzas();
LoadActions();
}
private static ReviewViewModel _instance;
private string _mainReviewScreen;
public static ReviewViewModel Instance
{
get { return _instance ?? (_instance = new ReviewViewModel()); }
}
public IViewAction ReviewPizzasAction { get; private set; }
public IViewAction ReviewSidesAction { get; private set; }
public string MainReviewScreen
{
get { return _mainReviewScreen; }
set
{
if (value == _mainReviewScreen) return;
_mainReviewScreen = value;
NotifyChanged("MainReviewScreen");
}
}
private void LoadActions()
{
ReviewPizzasAction = new ViewAction("Pizza Selection", execute: (a, o) => ReviewPizzas());
ReviewSidesAction = new ViewAction("Side Orders", execute: (a, o) => ReviewSides());
Actions.Add(new CloseCurrentViewAction(this, beginGroup: true));
}
private void ReviewPizzas()
{
MainReviewScreen = "PizzasPartialView";
}
private void ReviewSides()
{
MainReviewScreen = "Sides";
}
}
}
public IViewAction AddPizzaToCartAction { get; set; }
public IViewAction CustomizePizzaAction { get; set; }
private void LoadActions()
{
CustomizePizzaAction = new ViewAction(caption: "Customize This Pizza", execute: (action, o) => Controller.Message("Coming Soon!"));
AddPizzaToCartAction = new ViewAction(caption: "AddPizzaToCart", execute: (action, o) => Controller.Notification("Pizza Added to Cart!"));
SetParentActions();
}
private void SetParentActions()
{
Parent.Actions.Clear();
Parent.Actions.Add(AddPizzaToCartAction);
Parent.Actions.Add(CustomizePizzaAction);
Parent.Actions.Add(new CloseCurrentViewAction(Parent, beginGroup: true));
NotifyChanged();
}
public ReviewViewModel Parent { get; set; }
public ReviewPizzasViewModel()
{
Parent = ReviewViewModel.Instance;
LoadData();
LoadActions();
}
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using CODE.Framework.Wpf.Mvvm;
namespace AddActionsToParentViewModel.Client.Wpf.Models.Review
{
public class ReviewPizzasViewModel : ViewModel
{
public ReviewPizzasViewModel()
{
Parent = ReviewViewModel.Instance;
LoadData();
LoadActions();
}
public ReviewViewModel Parent { get; set; }
public ObservableCollection<ReviewPizzaDataViewModel> Pizzas { get; set; }
public ReviewPizzaDataViewModel SelectedPizza { get; set; }
public string SearchText { get; set; }
public IViewAction SearchAction { get; set; }
public IViewAction ClearFilterAction { get; set; }
public IViewAction AddPizzaToCartAction { get; set; }
public IViewAction CustomizePizzaAction { get; set; }
public IViewAction AddActionsAction { get; set; }
public IViewAction ClearActionsAction { get; set; }
private void LoadActions()
{
SearchAction = new ViewAction(caption: "Filter", execute: (action, o) => Controller.Notification("Filter happens here"));
ClearFilterAction = new ViewAction(caption: "Clear Filter", execute: (action, o) => Controller.Notification("Clear Filter"));
CustomizePizzaAction = new ViewAction(caption: "Customize This Pizza", execute: (action, o) => Controller.Message("Coming Soon!"));
AddPizzaToCartAction = new ViewAction(caption: "AddPizzaToCart", execute: (action, o) => Controller.Notification("Pizza Added to Cart!"));
SetParentActions();
}
private void SetParentActions()
{
Parent.Actions.Clear();
Parent.Actions.Add(AddPizzaToCartAction);
Parent.Actions.Add(CustomizePizzaAction);
Parent.Actions.Add(new CloseCurrentViewAction(Parent, beginGroup: true));
NotifyChanged();
}
private void LoadData()
{
Pizzas = new ObservableCollection<ReviewPizzaDataViewModel>(new List<ReviewPizzaDataViewModel>())
{
new ReviewPizzaDataViewModel {Id = Guid.NewGuid(), Name = "Cheesy Pizza", Description = "Pizza with lots of cheese"},
new ReviewPizzaDataViewModel {Id = Guid.NewGuid(), Name = "Pepperoni Pizza", Description = "Pizza with lots of pepperoni"},
new ReviewPizzaDataViewModel {Id = Guid.NewGuid(), Name = "Icky Pizza", Description = "Anything with pineapple"}
};
}
}
public class ReviewPizzaDataViewModel : StandardViewModel
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public override string Identifier1
{
get { return Id.ToString(); }
}
public override string Text1
{
get { return Name; }
}
public override string Text2
{
get { return Description; }
}
}
}
private void SetParentActions()
{
Parent.Actions.Clear();
Parent.Actions.Add(AddPizzaToCartAction);
Parent.Actions.Add(CustomizePizzaAction);
Parent.Actions.Add(new CloseCurrentViewAction(Parent, beginGroup: true));
NotifyChanged();
}
<Style TargetType="ItemsControl" x:Key="CODE.Framework-Layout-PrimarySecondaryFormLayout">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Layout:GridPrimarySecondary UIElementSpacing="5"
SecondaryAreaBackgroundBrush="{DynamicResource CODE.Framework-Application-ThemeBrush1}"
SecondaryAreaBackgroundBrushOpacity=".9"
SecondaryUIElementMargin="10"
PrimaryAreaBackgroundBrush="{DynamicResource CODE.Framework-Application-ThemeBrush1}"
PrimaryAreaBackgroundBrushOpacity=".9"
PrimaryUIElementMargin="10"
/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="{x:Null}" />
</Style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment