Weg's Blog

My adventures in programming

I started with the MVVM Wpf Ribbon sample released by Microsoft.

This is my style for RibbonTab notice IsSelected is bound to IsSelected in The view model.

I started with the MVVM Wpf Ribbon sample released by Microsoft.

This is my style for RibbonTab notice IsSelected is bound to IsSelected in The view model.

<!-- RibbonTab -->
<Style TargetType="{x:Type ribbon:RibbonTab}">
    <Setter Property="ContextualTabGroupHeader" Value="{Binding ContextualTabGroupHeader}" />
    <Setter Property="Header" Value="{Binding Header}" />
    <Setter Property="ItemsSource" Value="{Binding GroupDataCollection}" />
    <Setter Property="IsSelected" Value="{Binding IsSelected}" />
</Style>

This is in my view model code for the TabData.

        public bool IsSelected
        {
            get
            {
                return _isSelected;
            }
            set
            {
                if (_isSelected != value)
                {
                    _isSelected = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("IsSelected"));
                }
            }
        }
        private bool _isSelected;

In the constructor for the TabViewModel I take a parameter for the ViewModel of the content. And a public property to a bind to it.

public TabData(ISelectedContentTab content): this(content.DisplayName)
{
    _selectedContent = content;
}

private ISelectedContentTab _selectedContent;

public ISelectedContentTab SelectedContent
{
    get
    {
        return _selectedContent;
    }
}

Then I used an ItemsControl to display the selected content in my xaml

<ItemsControl Grid.Row="1" VerticalContentAlignment="Stretch" VerticalAlignment="Stretch"
ItemsSource="{Binding ElementName=ribbon,Path=SelectedItems}"
ItemTemplate="{StaticResource ContentControlTemplate}" />

And the ContentControlTemplate I have is

<DataTemplate x:Key="ContentControlTemplate">
  <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <ContentControl Grid.Row="0" VerticalAlignment="Stretch" Height="Auto" VerticalContentAlignment="Stretch" Content="{Binding SelectedContent}" />
  </Grid>
</DataTemplate>

Also make sure you have a datatemplate pointing your content to a view

Hope this helps some folks out!

I just installed XAML Power Toys for visual studio 2010 by Karl Shifflett and I am very excited to check it out I will post about my experiences with it.  Here are the features that it includes.

XAML Power Toys Full Feature Set

  • Create ViewModel Class - from a VB.NET or C# code window, easily create a ViewModel stub that includes commands and exposed data class.  Optionally you can elect to re-implement all Model properties on the ViewModel.
  • Create Silverlight DataForm For Selected Class - quickly create a DataForm complete with bindings that are easily associated with properties on the source class
  • Create WPF or Silverlight DataGrid For Selected Class - quickly create a DataGrid complete with bindings that are easily associated with properties on the source class
  • Create WPF ListView For Selected Class – quickly create a ListView complete with bindings that are easily associated with properties on the source class
  • Create Business Form For Selected Class – quickly create a form complete with bindings that are easily associated with properties on the source class
  • Create Business Form – quickly create a form without selecting an entity class.  Great for creating unbound forms or just laying out a Grid.
  • Show Fields List For Selected Class – display a list of class fields similar to Microsoft Access.  Allows dragging of fields to create controls
  • Extract Properties To Style – allows selecting a control, choosing desired properties and have those selected properties extracted to a newly created style
  • Group Into – allows selecting one or more controls and group them inside a new parent control.  Many options provided
  • Change Grid To Flow Layout – allows selecting of one of more control and will remove all MinWidth, MinHeight, Margin properties and will set all row and column definitions to Auto.
  • Chainsaw Minimize Cider Designer XAML – allows selecting of one or more controls and will remove all MinWidth, MinHeight, x:Name, Name, Margin properties and will set all row and column definitions to Auto.
  • Remove Margins – allows selecting one or more controls and removes the Margin property from them
  • Edit Grid Column and Rows – allows selecting a grid and then add or remove rows and columns
  • Set Defaults For Created Controls – allows customizing the initial properties that are set when the software creates a new control
  • About Box – see the version of XAML Power Toys installed on your system.  The current version of XAML Power Toys is always displayed at the top of this page below the title.

http://karlshifflett.wordpress.com/xaml-power-toys/

First post on my brand new blog!! Also my first time using wordpress, which I love.  Hopefully, I will finish setting up the blog this week.

In this blog I will be posting interesting things that I learn on the job (currently moving to WPF and .NET which I am very excited about! :) ) Also I will review various components, controls, and themes that I encounter.

Powered by WordPress Web Design by SRS Solutions © 2012 Weg's Blog Design by SRS Solutions