I try to make a "email messenger". I have two windows. Main window, there is ribbon with bookmarks and one button (New message). This button invoke second window NewMessage. The Mainwindow is owner of the NewMessage window.
MainWindow:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
NewMessage newmessage = new NewMessage();
newmessage.Show();
}
}
}
MainWindow XAML:
<Window x:Class="Messenger.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Messenger"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="New Message" Height="20" Width="80
" HorizontalAlignment="Left" Margin="35,46,0,0" VerticalAlignment="Top" Click="Button_Click" />
<TabControl HorizontalAlignment="Left" Height="254" Margin="34,44,0,0" VerticalAlignment="Top" Width="461" Background="{x:Null}" SelectedIndex="1">
<TabItem Header="Delivered" Visibility="Hidden" Width="80">
<Grid Background="#FFE5E5E5"/>
</TabItem>
<TabItem Header="Delivered" Visibility="Visible" Width="80">
<Grid Background="#FFE5E5E5"/>
</TabItem>
<TabItem Header="Sent" Width="80">
<Grid Background="#FFE5E5E5"/>
</TabItem>
<TabItem Header="Trash" Width="80">
<Grid Background="#FFE5E5E5"/>
</TabItem>
</TabControl>
</Grid>
NewMessage:
public partial class NewMessage : Window
{
public NewMessage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
NewMessage XAML:
<Window x:Class="Messenger.NewMessage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Messenger"
mc:Ignorable="d"
Title="NewMessage" Height="351.047" Width="814.398">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="27*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="23*"/>
<RowDefinition Height="24*"/>
<RowDefinition Height="243*"/>
<RowDefinition Height="31*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="Komu" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBox Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" />
<Label Grid.Row="1" Content="Předmět" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBox Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" />
<RichTextBox HorizontalAlignment="Left" Height="243" Grid.Row="2" VerticalAlignment="Top" Width="806" Grid.ColumnSpan="2">
<FlowDocument>
<Paragraph>
<Run Text="Sem zadejte text zprávy"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
<Button Grid.Row="3" Content="Odeslat" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="75" Margin="0,5,90,0"/>
<Button Grid.Row="3" Content="Storno" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="75" Margin="0,5,10,0" Click="Button_Click"/>
</Grid>
I would like to, when I minimize NewMessage window, this window minimize to the bottom of MainWindow "taskbar". If you know gmail, there is the same principle. Any idea?
Related
I have a problem where I run my program and it gives me a STA Error on my "Test" Window. It does not have an error if I don't have a timer going from the Page I am running till the window. I'll show and Example:
public Page1()
{
InitializeComponent();
Task.Delay(2000).ContinueWith(_ =>
{
var page = new TestW();
page.Show();
}
);
}
This is from my Page1 to open up my TestW ( Test Window )
My main code looks like this:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Luk_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void Button_Click(object sender, RoutedEventArgs e) // Login
{
Main.Content = new Page1();
Framep.Visibility = Visibility.Visible;
GridS.Visibility = Visibility.Hidden;
}
}
And my XAML Code:
<Window x:Class="date_app.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:date_app"
mc:Ignorable="d"
Title="MainWindow" Height="700" Width="400"
ResizeMode="NoResize"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
AllowsTransparency="True"
Background="Transparent"
>
<Border BorderBrush="Black"
BorderThickness="1.5"
CornerRadius="10"
>
<Border.Background>
<ImageBrush x:Name="ImageBrush" ImageSource="Images\bgapp.png" Stretch="None"/>
</Border.Background>
<Grid>
<StackPanel x:Name="Framep">
<Frame x:Name="Main" />
</StackPanel>
<StackPanel x:Name="GridS">
<!--X Luk Knappen.-->
<Grid>
<Button BorderBrush="Transparent" Name="Luk" Margin="360, 10, 10, 0" Background="Transparent" Click="Luk_Click">
<Button.Content>
<Image Source="Images\Ikke-navngivet.png" Height="20" Width="35" IsHitTestVisible="False" />
</Button.Content>
</Button>
</Grid>
<Grid>
<Image Source="Images\DateL.png" Height="200"/>
</Grid>
<!--Username.-->
<Grid>
<TextBox Style="{StaticResource WatermarkTextbox}" Name="Email" Height="30" Width="300" FontSize="20" FontFamily="Comic Sans MS" Text="Hello" Margin="0 40 0 0" TextChanged="Email_TextChanged"/>
</Grid>
<!--Password.-->
<Grid>
<TextBox Style="{StaticResource WatermarkTextbox1}" Name="Pass" Height="30" Width="300" FontSize="20" FontFamily="Comic Sans MS" Text="Hello" Margin="0 35 0 0" TextChanged="Pass_TextChanged"/>
</Grid>
<!--Login Knap.-->
<Grid>
<Button Grid.Column="0" Content="Log ind" Width="80" Height="30" FontSize="20" Margin="0 100 0 0" Click="Button_Click" />
</Grid>
<!--Opret Bruger-->
<Grid>
<Button Grid.Column="0" Content="Opret Bruger" Width="140" Height="30" FontSize="20" Margin="0 20 0 0" />
</Grid>
</StackPanel>
</Grid>
</Border>
Page1 Code:
<Page x:Class="date_app.Page1"
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"
xmlns:gif="https://github.com/XamlAnimatedGif/XamlAnimatedGif"
xmlns:local="clr-namespace:date_app"
mc:Ignorable="d"
d:DesignHeight="700" d:DesignWidth="400"
Title="LoadingM">
<Border BorderBrush="Black"
BorderThickness="1.5"
CornerRadius="10"
>
<Border.Background>
<ImageBrush x:Name="ImageBrush" ImageSource="Images\bgapp.png" Stretch="None"/>
</Border.Background>
<Grid>
<TextBlock Text="LOADING. . ." FontSize="50" FontFamily="Comic Sans MS"/>
<Image gif:AnimationBehavior.SourceUri="Images\CatGif.gif" />
</Grid>
</Border>
The problem I have: If I run with the Task Delay My test Window gets an STA Error that I don't know how to fix.
If I run without the Task Delay It just opens it all up but no STA Error.
I am trying to do this:
When I press on the Login button It is supposed to open the Page1 and hide the main window for a " Loading " Screen and then after the delay to close Main window + Page1 down to Open up the New Window. Been sitting with this for a little while :) Thanks in advance!
-- Test Window Is plain. No code there.
This is the Background.
The problem is that the Action given to ContinueWith will not be exectued on the UiThread but on a free ThreadPool-Thread, so the new TestW object will be constructed and used by a non STA-Thread. But any WPF-UI-component must be constructed and used by an STA-Thread.
The solution is to replace your Task.Delay() with
Task.Delay(2000).ContinueWith(_ =>
{
Dispatcher.Invoke(() =>
{
var page = new TestW();
page.Show();
});
});
This will delegate your execution back to the UiThread.
I need to insert data from usercontrol into database.
I tried to set xml component into my model but it results in System.NullReferenceException.
Where is the problem ? How can I solve this?
usercontrol.cs:
public partial class League : UserControl
{
private Leagues _leagueVM;
public Leagues LeagueVM
{
get
{
_leagueVM.EnLeagueName = txtLeagueNameEN.Text;
_leagueVM.FaLeagueName = txtLeagueNameFA.Text;
_leagueVM.LeagueLogo = imgLogoLeague.Name;
return _leagueVM;
}
set
{
txtLeagueNameEN.Text = _leagueVM.EnLeagueName;
txtLeagueNameFA.Text = _leagueVM.FaLeagueName;
imgLogoLeague.Name = _leagueVM.LeagueLogo;
}
}
public League()
{
var leagueManager = Inject.Container.GetInstance<ILeagueService>();
InitializeComponent();
}
private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
FileDialog dialog = new OpenFileDialog();
dialog.ShowDialog();
}
private void btnInsertLeague_Click(object sender, RoutedEventArgs e)
{
var leagueManager = Inject.Container.GetInstance<ILeagueService>();
leagueManager.Add(LeagueVM);
}
}
xml:
<UserControl x:Class="Bet.UControl.UControls.League"
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"
xmlns:local="clr-namespace:Bet.UControl.UControls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Width="1255" Height="624">
<Grid Margin="10,0,10,10">
<GroupBox Header="New League" Background="#fff" HorizontalAlignment="Center" Height="151" Margin="10,10,0,0" VerticalAlignment="Top" Width="1215">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Label Content="LeagueName (En) : " Foreground="Black" Width="111" FontFamily="Rockwell" Height="28"/>
<TextBox x:Name="txtLeagueNameEN" Width="199" Height="30" Margin="10,20,30,40" />
<Label Content="LeagueName (En) : " Foreground="Black" Width="111" FontFamily="Rockwell" Height="28"/>
<TextBox x:Name="txtLeagueNameFA" Width="199" Height="30" Margin="10,20,30,40" />
<Label Content="League Logo " Foreground="Black" Width="111" FontFamily="Rockwell" Height="28"/>
<Image x:Name="imgLogoLeague" Width="90" Height="85" Margin="5,0,0,0" Source="E:\MyProject\Bet\Bet\Assetes\adfg.png" MouseDown="Image_MouseDown"/>
<Button x:Name="btnInsertLeague" Content="Add" Height="Auto" Width="75" Margin="100,27,30,43" Click="btnInsertLeague_Click"/>
</StackPanel>
</GroupBox>
<DataGrid HorizontalAlignment="Left" Height="420" Margin="15,184,0,0" VerticalAlignment="Top" Width="1210"/>
</Grid>
It seems you missed to create a Leagues object and assign it to _leagueVM.
Should be easy to see if you use the debugger.
I've created a simple custom messagebox that automatically scales depending on the length of the text to be displayed :
public partial class CustomMessageBox : Window
{
public CustomMessageBox(string title, string text)
{
InitializeComponent();
ResizeMode = ResizeMode.NoResize;
label.Content = text;
Title = title;
}
public static void Show(string title, string text)
{
CustomMessageBox box = new CustomMessageBox(title, text);
box.SizeToContent = SizeToContent.WidthAndHeight;
box.ShowDialog();
}
private void button_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
This works nicely however my button is clamping to the bottom side of the window because the window automatically scales :
And the button seems to be moving once the message gets longer :
How would I make sure the button stays centered and have a margin of around 10px from the bottom so it doesn't look that clamped?
I tried to set the Margin manually but that doesn't seem to work.
XAML (largely generated by the designer) :
<Window x:Class="RapidEvent.CustomMessageBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RapidEvent"
mc:Ignorable="d"
Background="{DynamicResource WindowBackgroundBrush}"
Title="" Height="Auto" Width="Auto">
<Grid>
<StackPanel>
<Label x:Name="label" Content="" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" FontSize="13px" RenderTransformOrigin="0.392,0.486"/>
<Button x:Name="button" x:FieldModifier="public" IsDefault="True" Content="_Ok" HorizontalAlignment="Left" Margin="110,40,0,0" VerticalAlignment="Top" Width="80" Height="21" Click="button_Click"/>
</StackPanel>
</Grid>
</Window>
Simply change your StackPanel to a Grid and the HorizonalAlignment of your button to Center and take off all but the bottom margin. You'll also need to set the VerticalAlignment to Bottom. You also need to put the button on row 1.
This way the button will be clamped to the bottom of the dialog and always centred.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label x:Name="label" Content=""
HorizontalAlignment="Left" Margin="10,0,0,0"
VerticalAlignment="Top" FontSize="13px"
RenderTransformOrigin="0.392,0.486"/>
<Button Grid.Row="1" x:Name="button" x:FieldModifier="public"
IsDefault="True" Content="_Ok"
HorizontalAlignment="Center" Margin="0,0,0,20"
VerticalAlignment="Bottom" Width="80" Height="21"/>
</Grid>
Use grid instead of StackPanel:
<Grid >
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<telerik:Label x:Name="label" Content="LSFFD" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" FontSize="13px" RenderTransformOrigin="0.392,0.486"/>
<Button Grid.Row="1" x:Name="button" x:FieldModifier="public" Content="_Ok" HorizontalAlignment="Center" Margin="0 0 0 10" VerticalAlignment="Bottom" Width="80" Height="21" Click="button_Click"/>
</Grid>
I'm creating a win8 app and I need to change the layout of my grid so everything fits on screen when the user flips between orientations. I understand I need to use VisualStateManager but I can't understand any tutorials. If I have this code:
<Grid>
<Button x:Name="button1" Margin="188,73,286,0" VerticalAlignment="Top"/>
<Button x:Name="button2" Margin="236,73,238,0" VerticalAlignment="Top"/>
<Button x:Name="button3" Margin="284,73,190,0" VerticalAlignment="Top"/>
</Grid>
How would I use visual state manager to change the buttons so they are now orientated in a column (one above the other) instead of in a row when the orientation is changed to portrait from landscape?
Thanks
xaml code
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" SizeChanged="Page_SizeChanged_1">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="FullScreenLandscape">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button Content="Button1" HorizontalAlignment="Center" VerticalAlignment="Center"></Button>
<Button Content="Button2" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"></Button>
<Button Content="Button3" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center"></Button>
</Grid>
<Grid x:Name="Snapped">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Button Content="Button1" HorizontalAlignment="Center" VerticalAlignment="Center"></Button>
<Button Content="Button2" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center"></Button>
<Button Content="Button3" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center"></Button>
</Grid>
</Grid>
C# code
private void Page_SizeChanged_1(object sender, SizeChangedEventArgs e)
{
switch (ApplicationView.Value)
{
case ApplicationViewState.FullScreenLandscape:
VisualStateManager.GoToState(this, "FullScreenLandscape", false);
Snapped.Visibility = Visibility.Collapsed;
break;
case ApplicationViewState.Snapped:
VisualStateManager.GoToState(this, "Snapped", false);
FullScreenLandscape.Visibility = Visibility.Collapsed;
Snapped.Visibility = Visibility.Visible;
break;
default:
return;
}
}
Another Method
xaml code
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="landscape">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBox x:Name="t1" Grid.Column="0" FontSize="24" Height="100"/>
<TextBox x:Name="t2" Grid.Column="1" FontSize="24" Height="100"/>
<TextBox x:Name="t3" Grid.Column="2" FontSize="24" Height="100"/>
</Grid>
<Grid x:Name="snap" Visibility="Collapsed">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
</Grid>
</Grid>
C# code
private void Page_SizeChanged_1(object sender, SizeChangedEventArgs e)
{
if (Windows.UI.ViewManagement.ApplicationView.Value == Windows.UI.ViewManagement.ApplicationViewState.FullScreenLandscape)
{
landscape.Visibility = Windows.UI.Xaml.Visibility.Visible;
snap.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
t1.SetValue(Grid.ColumnProperty, 0);
t2.SetValue(Grid.ColumnProperty, 1);
if (t1.Parent != landscape)
{
snap.Children.Remove(t1);
snap.Children.Remove(t2);
landscape.Children.Add(t1);
landscape.Children.Add(t2);
}
}
else if(Windows.UI.ViewManagement.ApplicationView.Value == Windows.UI.ViewManagement.ApplicationViewState.Snapped)
{
landscape.Children.Remove(t1);
landscape.Children.Remove(t2);
landscape.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
snap.Visibility = Windows.UI.Xaml.Visibility.Visible;
t1.SetValue(Grid.RowProperty, 0);
t2.SetValue(Grid.RowProperty, 1);
if (t1.Parent != snap)
{
landscape.Children.Remove(t1);
landscape.Children.Remove(t2);
snap.Children.Add(t1);
snap.Children.Add(t2);
}
}
}
I am trying to learn c# and WPF application. Here I am trying to redirect from one WPF page(MainWindow.xaml) to another(HandWash.xaml) on a button click event. But the following code is throwing NULLReferenceException.
This is the MainWindow.xaml file.
<Window x:Class="MyApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
d:DesignHeight="720" d:DesignWidth="1284"
Title="StartPage" WindowStartupLocation="CenterScreen" WindowStyle="None" WindowState="Maximized" Closed="Window_Closed">
<Window.Background>
<ImageBrush ImageSource="/Images/StartPage.png"></ImageBrush>
</Window.Background>
<Grid>
<Button Content="Hand Wash" Height="794" HorizontalAlignment="Left" Name="HandWash" VerticalAlignment="Top" Width="353" FontSize="50" Background="Transparent" BorderThickness="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Click="HandWash_Click"/>
<Button Content="Bathing" Height="794" HorizontalAlignment="Left" Margin="390,0,0,0" Name="Bathing" VerticalAlignment="Top" Width="301" FontSize="50" Background="Transparent" BorderThickness="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Click="Bathing_Click"/>
<Button Content="Nail-Clip" Height="794" HorizontalAlignment="Left" Margin="730,0,0,0" Name="NailClip" VerticalAlignment="Top" Width="295" FontSize="50" Background="Transparent" BorderThickness="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Click="NailClip_Click"/>
<Button Content="Teeth Brush" Height="794" HorizontalAlignment="Left" Margin="1067,0,0,0" Name="TeethBrush" VerticalAlignment="Top" Width="310" FontSize="50" Background="Transparent" BorderThickness="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Click="TeethBrush_Click"/>
</Grid>
</Window>
Background code for this:
private void TeethBrush_Click(object sender, RoutedEventArgs e)
{
try
{
TeethBrush teeth = new TeethBrush(myarg);
NavigationService navService = NavigationService.GetNavigationService(this);
navService.Navigate(teeth); // NULL REFERENCE EXCEPTION at this line
}
catch (NullReferenceException ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
}
This is the code for TeethBrush.xaml :
<Page x:Class="MyApplication.TeethBrush"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
d:DesignHeight="720" d:DesignWidth="1284"
Title="TeethBrush">
<Grid>
</Grid>
<Page.Background>
<ImageBrush ImageSource="C:\Users\Tonmoy\Documents\Visual Studio 2010\Projects\MyKinectApp\MyKinectApp\Images\StartPage.png"></ImageBrush>
</Page.Background>
</Page>
and the background code is:
public TeethBrush(Myargs arg)
{
InitializeComponent();
//Rest of the code
}
Please help....
You need to have a frame in main window where contents of Pages will be hosted.
If you add the following namespace to MainWindow:
xmlns:local="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
you can define a frame somewhere, e.g. in your grid:
<Grid>
<local:Frame x:Name="mainFrame">
</local:Frame>
....
Then you can navigate from your event handler like so:
TeethBrush teeth = new TeethBrush(myarg);
this.mainFrame.Navigate(teeth);