Advertisement
Guest User

Untitled

a guest
Jan 20th, 2016
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.90 KB | None | 0 0
  1. --MainWindow.xaml
  2. <Window x:Class="WPFTestProject.MainWindow"
  3.         x:Name="MainDialog"
  4.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  5.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  6.         xmlns:us="clr-namespace:WPFTestProject"
  7.         Title="MainWindow" Height="200" Width="350">
  8.  
  9.     <Grid>
  10.         <Grid.Effect>
  11.             <BlurEffect Radius="{Binding BlurRadius}" />
  12.         </Grid.Effect>
  13.         <TabControl ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab}">
  14.             <TabControl.ItemContainerStyle>
  15.                 <Style TargetType="TabItem">
  16.                     <Setter Property="Header" Value="{Binding Header}" />
  17.                 </Style>
  18.             </TabControl.ItemContainerStyle>
  19.             <TabControl.Resources>
  20.                 <!-- TODO: Need to add two more DataTemplates here once the second and third tabs are implemented -->
  21.                 <DataTemplate DataType="{x:Type us:FirstTabViewModel}">
  22.                     <us:FirstTabUserControl />
  23.                 </DataTemplate>
  24.                 <DataTemplate DataType="{x:Type us:SecondTabViewModel}">
  25.                     <us:SecondTabUserControl />
  26.                 </DataTemplate>
  27.             </TabControl.Resources>
  28.         </TabControl>
  29.     </Grid>
  30. </Window>
  31.  
  32. --MainWindowViewModel.cs
  33. using System.Collections.ObjectModel;
  34.  
  35. namespace WPFTestProject
  36. {
  37.     public interface ITab
  38.     {
  39.         string Header { get; set; }
  40.     }
  41.  
  42.     public class MainWindowViewModel : ObservableObject
  43.     {
  44.         private double _blurRadius;
  45.         public double BlurRadius
  46.         {
  47.             get { return _blurRadius; }
  48.             set
  49.             {
  50.                 _blurRadius = value;
  51.                 RaisePropertyChanged( "BlurRadius" );
  52.             }
  53.         }
  54.  
  55.         private ObservableCollection<ITab> _tabs;
  56.         public ObservableCollection<ITab> Tabs
  57.         {
  58.             get { return _tabs; }
  59.             set
  60.             {
  61.                 _tabs = value;
  62.                 RaisePropertyChanged( "Tabs" );
  63.             }
  64.         }
  65.  
  66.         private ITab _selectedTab;
  67.         public ITab SelectedTab
  68.         {
  69.             get
  70.             {
  71.                 return _selectedTab;
  72.             }
  73.             set
  74.             {
  75.                 _selectedTab = value;
  76.                 RaisePropertyChanged( "SelectedTab" );
  77.             }
  78.         }
  79.  
  80.         public MainWindowViewModel()
  81.         {
  82.             // Start off with no blur
  83.             this.BlurRadius = 0;
  84.  
  85.             this.Tabs = new ObservableCollection<ITab>();
  86.             this.Tabs.Add( new FirstTabViewModel() { Header = "First Tab" } );
  87.             this.Tabs.Add( new SecondTabViewModel() { Header = "Second Tab" } );
  88.             this.SelectedTab = this.Tabs[ 0 ];
  89.         }
  90.     }
  91. }
  92.  
  93. --FirstTabUserControl.xaml
  94. <UserControl x:Class="WPFTestProject.FirstTabUserControl"
  95.              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  96.              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  97.              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  98.              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  99.              mc:Ignorable="d"
  100.              d:DesignHeight="200" d:DesignWidth="350">
  101.     <Grid>
  102.         <Button Content="Press Me! (#1)" Command="{Binding PressButtonCommand}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="95" />
  103.     </Grid>
  104. </UserControl>
  105.  
  106.  
  107. --FirstTabViewModel.cs
  108. namespace WPFTestProject
  109. {
  110.     public class FirstTabViewModel : ITab
  111.     {
  112.         public string Header { get; set; }
  113.  
  114.         public RelayCommand PressButtonCommand { get; set; }
  115.  
  116.         public FirstTabViewModel()
  117.         {
  118.             this.PressButtonCommand = new RelayCommand( this.HandleButtonPress, () => true );
  119.         }
  120.  
  121.         private void HandleButtonPress()
  122.         {
  123.  
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement