Friday, 2 March 2012

Displaying Madular content using WPF





 * code for design file

<Window x:Class="LayoutPanels.ModularContent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ModularContent" Height="362" Width="516"   
    >
  <ScrollViewer>
  <StackPanel>
  <WrapPanel Background="LightSteelBlue" Name="pnlList">
    <CheckBox Margin="5" IsChecked="True">Panel1</CheckBox>
    <CheckBox Margin="5" IsChecked="True">Panel2</CheckBox>
    <CheckBox Margin="5" IsChecked="True">Panel3</CheckBox>
    <CheckBox Margin="5" IsChecked="True">Panel4</CheckBox>
  </WrapPanel>
   
  <WrapPanel>
    <StackPanel Name="Panel1" >
    <Border Padding="5" BorderBrush="Yellow" BorderThickness="2">
      <UniformGrid Rows="2" Columns="2">
        <Button Margin="10" Padding="10">1</Button>
        <Button Margin="10" Padding="10">2</Button>
        <Button Margin="10" Padding="10">3</Button>
        <Button Margin="10" Padding="10">4</Button>
      </UniformGrid>
    </Border>
    </StackPanel>
   
    <StackPanel Name="Panel2">
      <Border Padding="15" BorderBrush="Yellow" BorderThickness="2">
      <TabControl>
        <TabItem Header="Page1">
          <Button Padding="100,50,100,50">Tabs</Button>
        </TabItem>
        <TabItem Header="Page2">         
        </TabItem>       
      </TabControl>
      </Border>
    </StackPanel>

    <StackPanel Name="Panel3">
      <Border Padding="15" BorderBrush="Yellow" BorderThickness="2">
        <StackPanel>
          <TextBox MinLines="5" MaxWidth="150" TextWrapping="Wrap">This is a test of a text box that contains wrapped text.</TextBox>
          <StackPanel Orientation="Horizontal">
            <Button>OK</Button>
            <Button>Cancel</Button>
          </StackPanel>
        </StackPanel>
      </Border>
    </StackPanel>

    <StackPanel Name="Panel4">
      <Border Padding="15" BorderBrush="Yellow" BorderThickness="2">
        <UniformGrid Rows="2" Columns="2">
          <Button Margin="10" Padding="10">1</Button>
          <Button Margin="10" Padding="10">2</Button>
          <Button Margin="10" Padding="10">3</Button>
          <Button Margin="10" Padding="10">4</Button>
        </UniformGrid>
      </Border>
    </StackPanel>
  </WrapPanel>
   
  </StackPanel>
  </ScrollViewer>
</Window>

* code file
using System;
using System.Collections.Generic;
using System.Text;
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;
using System.Windows.Xps.Packaging;
using System.IO;

namespace LayoutPanels
{
    /// <summary>
    /// Interaction logic for ModularContent.xaml
    /// </summary>

    public partial class ModularContent : System.Windows.Window
    {

        public ModularContent()
        {
            InitializeComponent();

            AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(chk_Checked));
            AddHandler(CheckBox.UncheckedEvent, new RoutedEventHandler(chk_Unchecked));           
        }

        private void chk_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox chk = (CheckBox)e.OriginalSource;
            DependencyObject obj = LogicalTreeHelper.FindLogicalNode(this, chk.Content.ToString());
            ((FrameworkElement)obj).Visibility = Visibility.Visible;
        }

        private void chk_Unchecked(object sender, RoutedEventArgs e)
        {
            CheckBox chk = (CheckBox)e.OriginalSource;
            DependencyObject obj = LogicalTreeHelper.FindLogicalNode(this, chk.Content.ToString());
            ((FrameworkElement)obj).Visibility = Visibility.Collapsed;
        }
    }
}

No comments:

Post a Comment