Skip to content

Instantly share code, notes, and snippets.

/MainWindow.xaml Secret

Created November 2, 2010 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/684032cbcea285ab82f5 to your computer and use it in GitHub Desktop.
Save anonymous/684032cbcea285ab82f5 to your computer and use it in GitHub Desktop.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Wpf.Controls;assembly=Wpf.TabControl"
xmlns:local="clr-namespace:__I_MVVM"
xmlns:local1="clr-namespace:__I_MVVM.Views"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="__I_MVVM.MainWindow"
x:Name="Window"
Title="3-I Inventory System" Height="700" Width="1275" WindowState="Maximized">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="{Binding ScreenWidth}"/>
</Grid.ColumnDefinitions>
<!-- Content for Grid Column = 0-->
<Frame Grid.Column="0" Height="{Binding ScreenHeight}" HorizontalAlignment="Left" x:Name="frame2" VerticalAlignment="Top" Width="200" />
<!-- Content for Grid Column 1-->
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="0.083*"/>
<RowDefinition Height="0.917*"/>
<RowDefinition Height="15"/>
</Grid.RowDefinitions>
<r:TabControl x:Name="tabControl" TabStripPlacement="{Binding SelectedItem, ElementName=listBox}"
TabItemMinWidth="150" TabItemMaxWidth="300" TabItemMinHeight="30" TabItemMaxHeight="50" VerticalContentAlignment="Center" Grid.RowSpan="2" Foreground="#FF4B4847" BorderBrush="#FF646464">
<r:TabControl.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
<GradientStop Color="White" Offset="0.498"/>
</LinearGradientBrush>
</r:TabControl.Background>
<!-- Properties for setting the background for the tab items depending on their current state -->
<!-- These brushes give the contro an IE7 type look-->
<r:TabControl.TabItemNormalBackground>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFFCFDFD" Offset="0"/>
<GradientStop Color="#FFE5EAF5" Offset="0.3"/>
<GradientStop Color="#FFCFD7EB" Offset="0.3"/>
<GradientStop Color="#FFE0E5F5" Offset="0.7"/>
<GradientStop Color="#FFECEEFC" Offset="1"/>
</LinearGradientBrush>
</r:TabControl.TabItemNormalBackground>
<r:TabControl.TabItemSelectedBackground>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFFBFDFE" Offset="0"/>
<GradientStop Color="#FFEAF6FB" Offset="0.3"/>
<GradientStop Color="#FFCEE7FA" Offset="0.3"/>
<GradientStop Color="#FFB9D1FA" Offset="1"/>
</LinearGradientBrush>
</r:TabControl.TabItemSelectedBackground>
<r:TabControl.TabItemMouseOverBackground>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFFCFDFD" Offset="0"/>
<GradientStop Color="#FFC6DDF7" Offset="0.3"/>
<GradientStop Color="#FF99C6EE" Offset="0.3"/>
<GradientStop Color="#FFB6D6F1" Offset="0.7"/>
<GradientStop Color="#FFD9E9F9" Offset="1"/>
</LinearGradientBrush>
</r:TabControl.TabItemMouseOverBackground>
<!--
Note, if you Set the Width/MaxWidth/MinWidth properties on individual tab items as shown below, these values will be ignored by the
build in auto tabitem sizing implementation of the TabControl.
to set size constraints you should use the TabItemMinWidth/TabItemMaxWidth/TabItemMinHeight/TabItemMaxHeight properties of the TabControl to set size constraints
on tab items, these values apply to ALL Tabitems in the Control.
-->
<r:TabItem x:Name="tabOne" Width="350" MaxWidth="250" MinWidth="250" BorderBrush="#FFE0E0E0">
<!--
we could use the header attribute to set the header if it is text
but wrapping it in a textblock gives use character ellipsis and wrapping options etc
-->
<r:TabItem.Header>
<TextBlock Text="Homepage" Name="tabOneHeader" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" FontSize="18" />
</r:TabItem.Header>
<!-- Add an Icon to the TabItem, this con is also used in the DropDown context menu-->
<r:TabItem.Icon>
<Image Source="/Images/ie.ico" Height="16" Width="16" Margin="2,0,2,0" VerticalAlignment="Center"/>
</r:TabItem.Icon>
<!-- The TabItem content is a Windows Forms WebBrowser object wrapped in a WindowsFormsHost-->
<r:TabItem.Content>
<local:test/>
</r:TabItem.Content>
</r:TabItem>
</r:TabControl>
<Rectangle x:Name="rectangle1" Grid.Row="2" d:LayoutOverrides="GridBox">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF3B0000" Offset="1"/>
<GradientStop Color="#FF6C0000" Offset="0.434"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Foreground="White" Grid.Row="2" Height="15" HorizontalAlignment="Left" Margin="879,0,0,0" x:Name="textBlock1" Text="Current User:" VerticalAlignment="Top" FontWeight="Bold" TextAlignment="Right" />
<TextBlock FontWeight="Bold" Foreground="White" Height="15" HorizontalAlignment="Left" Margin="972,0,0,0" x:Name="textBlock2" Text="Administrator" TextAlignment="Right" VerticalAlignment="Top" Grid.Row="2" />
<Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="332,6,0,0" Name="label1" VerticalAlignment="Top" />
</Grid>
</Grid>
</Window>
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 UI_3_i;
using __I_MVVM.Views;
using __I_MVVM;
namespace @__I_MVVM
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public string Text;
double ScreenHeight = System.Windows.SystemParameters.PrimaryScreenHeight - 20;
double ScreenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
MainPageLeftMainFrame LF = new MainPageLeftMainFrame();
MainPageRightSalesFrame RF = new MainPageRightSalesFrame();
public MainWindow()
{
InitializeComponent();
frame2.Navigate(new Uri(@"Views/MainPageLeftMainFrame.xaml", UriKind.Relative));
//frame1.Navigate(new Uri(@"/MainPageRightSalesFrame.xaml", UriKind.Relative));
//frame1.Source = new Uri(@"Views/MainPageRightMainFrame.xaml", UriKind.Relative);
tabControl.TabItemAdded += tabControl_TabItemAdded;
tabControl.SelectionChanged += tabControl_SelectionChanged;
// these 3 events ensure that all the contents of the textbox are selected on a mouseclick (as per IE)
// code borrowed from the Windows Presentation Foundation Forum at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2199428&SiteID=1
//textBox.GotKeyboardFocus += delegate(object sender, KeyboardFocusChangedEventArgs e)
//{
// System.Windows.Controls.TextBox tb = (sender as System.Windows.Controls.TextBox);
// if (tb != null)
// tb.SelectAll();
//};
//textBox.MouseDoubleClick += delegate(object sender, MouseButtonEventArgs e)
//{
// System.Windows.Controls.TextBox tb = (sender as System.Windows.Controls.TextBox);
// if (tb != null)
// tb.SelectAll();
//};
//textBox.PreviewMouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
//{
// System.Windows.Controls.TextBox tb = (sender as System.Windows.Controls.TextBox);
// if (tb != null)
// {
// if (!tb.IsKeyboardFocusWithin)
// {
// e.Handled = true;
// tb.Focus();
// }
// }
//};
}
private int count = 1;
private int tabcount = 2;
private int framecount = 3;
void tabControl_TabItemAdded(object sender, Wpf.Controls.TabItemEventArgs e)
{
// Add an Icon to the tabItem
BitmapImage image = new BitmapImage(new Uri("pack://application:,,,/3-I-MVVM;component/Images/ie.ico"));
Image img = new Image();
img.Source = image;
img.Width = 16;
img.Height = 16;
img.Margin = new Thickness(2, 0, 2, 0);
e.TabItem.Icon = img;
// wrap the header in a textblock, this gives us the character ellipsis (...) when trimmed
TextBlock tb = new TextBlock();
tb.Text = "New Tab " + count++;
tb.TextTrimming = TextTrimming.CharacterEllipsis;
tb.TextWrapping = TextWrapping.NoWrap;
e.TabItem.Header = tb;
// add a WebControl to the TAbItem
//Frame host = new Frame();
//host.Name = "frame" + framecount.ToString();
////WindowsFormsHost host = new WindowsFormsHost();
////host.Margin = new Thickness(2);
////System.Windows.Forms.WebBrowser browser = new System.Windows.Forms.WebBrowser();
////browser.DocumentTitleChanged += Browser_DocumentTitleChanged;
////browser.Navigated += Browser_Navigated;
////host.Child = browser;
//host.Navigate(new Uri(@"/Views/MainPageRightMainFrame.xaml", UriKind.Relative));
test1 host = new test1();
e.TabItem.Name = "tab" + tabcount.ToString();
e.TabItem.Content = host;
}
void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
void Browser_DocumentTitleChanged(object sender, EventArgs e)
{
System.Windows.Forms.WebBrowser browser = sender as System.Windows.Forms.WebBrowser;
if (browser == null) return;
// update the TabItems's Header property
Wpf.Controls.TabItem item = tabControl.SelectedItem as Wpf.Controls.TabItem;
// Add an Icon to the tabItem
BitmapImage image = new BitmapImage(new Uri("pack://application:,,,/Test;component/Images/ie.ico"));
Image img = new Image();
img.Source = image;
img.Width = 16;
img.Height = 16;
img.Margin = new Thickness(2, 0, 2, 0);
if (item != null) item.Icon = img;
// wrap the header in a textblock, this gives us the character ellipsis (...) when trimmed
TextBlock tb = new TextBlock();
tb.Text = browser.DocumentTitle;
tb.TextTrimming = TextTrimming.CharacterEllipsis;
tb.TextWrapping = TextWrapping.NoWrap;
if (item != null) item.Header = tb;
}
//void textBox1_TextChanged(object sender, TextChangedEventArgs e)
//{
// RF.textBox1.Text = "LEO";
//}
//private void button1_Click(object sender, RoutedEventArgs e)
//{
// ViewModel VM = new ViewModel();
//}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
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.Navigation;
using System.Windows.Shapes;
using System.Reflection;
namespace __I_MVVM
{
/// <summary>
/// Interaction logic for salesBtn.xaml
/// </summary>
public partial class test : UserControl
{
public test()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MainWindow MW = Application.Current.MainWindow as MainWindow;
MW.label1.Content = MW.tabControl.SelectedIndex;
TabItem page = MW.tabControl.SelectedItem as TabItem;
test1 a = MW.test;
// this.Dispatcher.Invoke((System.Windows.Forms.MethodInvoker)delegate { a.frame1.Navigate(new Uri(@"/UserControls/salesBtn.xaml", UriKind.Relative)); });
a.Frame1Navigate(new Uri(@"/UserControls/salesBtn.xaml", UriKind.Relative));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
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.Navigation;
using System.Windows.Shapes;
using __I_MVVM.Views;
namespace __I_MVVM
{
/// <summary>
/// Interaction logic for test1.xaml
/// </summary>
public partial class test1 : UserControl
{
public delegate void testclassBack(UserControl uc);
MainWindow MW = Application.Current.MainWindow as MainWindow;
public test1()
{
InitializeComponent();
this.frame1.Content = new MainPageRightMainFrame();
}
public void Frame1Navigate(Uri mySource)
{ this.frame1.Navigate(mySource /*, UriKind.Relative */); }
}
}
<UserControl x:Class="__I_MVVM.test1"
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="690" d:DesignWidth="1050">
<Grid>
<Frame Height="690" HorizontalAlignment="Left" Name="frame1" VerticalAlignment="Top" Width="1050" >
</Frame>
</Grid>
</UserControl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment