Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --MainWindow.xaml
- <Window x:Class="WPFTestProject.MainWindow"
- x:Name="MainDialog"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:us="clr-namespace:WPFTestProject"
- Title="MainWindow" Height="200" Width="350">
- <Grid>
- <Grid.Effect>
- <BlurEffect Radius="{Binding BlurRadius}" />
- </Grid.Effect>
- <TabControl ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab}">
- <TabControl.ItemContainerStyle>
- <Style TargetType="TabItem">
- <Setter Property="Header" Value="{Binding Header}" />
- </Style>
- </TabControl.ItemContainerStyle>
- <TabControl.Resources>
- <!-- TODO: Need to add two more DataTemplates here once the second and third tabs are implemented -->
- <DataTemplate DataType="{x:Type us:FirstTabViewModel}">
- <us:FirstTabUserControl />
- </DataTemplate>
- <DataTemplate DataType="{x:Type us:SecondTabViewModel}">
- <us:SecondTabUserControl />
- </DataTemplate>
- </TabControl.Resources>
- </TabControl>
- </Grid>
- </Window>
- --MainWindowViewModel.cs
- using System.Collections.ObjectModel;
- namespace WPFTestProject
- {
- public interface ITab
- {
- string Header { get; set; }
- }
- public class MainWindowViewModel : ObservableObject
- {
- private double _blurRadius;
- public double BlurRadius
- {
- get { return _blurRadius; }
- set
- {
- _blurRadius = value;
- RaisePropertyChanged( "BlurRadius" );
- }
- }
- private ObservableCollection<ITab> _tabs;
- public ObservableCollection<ITab> Tabs
- {
- get { return _tabs; }
- set
- {
- _tabs = value;
- RaisePropertyChanged( "Tabs" );
- }
- }
- private ITab _selectedTab;
- public ITab SelectedTab
- {
- get
- {
- return _selectedTab;
- }
- set
- {
- _selectedTab = value;
- RaisePropertyChanged( "SelectedTab" );
- }
- }
- public MainWindowViewModel()
- {
- // Start off with no blur
- this.BlurRadius = 0;
- this.Tabs = new ObservableCollection<ITab>();
- this.Tabs.Add( new FirstTabViewModel() { Header = "First Tab" } );
- this.Tabs.Add( new SecondTabViewModel() { Header = "Second Tab" } );
- this.SelectedTab = this.Tabs[ 0 ];
- }
- }
- }
- --FirstTabUserControl.xaml
- <UserControl x:Class="WPFTestProject.FirstTabUserControl"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- mc:Ignorable="d"
- d:DesignHeight="200" d:DesignWidth="350">
- <Grid>
- <Button Content="Press Me! (#1)" Command="{Binding PressButtonCommand}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="95" />
- </Grid>
- </UserControl>
- --FirstTabViewModel.cs
- namespace WPFTestProject
- {
- public class FirstTabViewModel : ITab
- {
- public string Header { get; set; }
- public RelayCommand PressButtonCommand { get; set; }
- public FirstTabViewModel()
- {
- this.PressButtonCommand = new RelayCommand( this.HandleButtonPress, () => true );
- }
- private void HandleButtonPress()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement