Setting window title to page title - c#

I'm currently trying to display the current page title as window title. my MainWindow.xaml:
<Window x:Class="Your_choice_1.MainWindow"
namespace:"Your_choice_1"
mc:Ignorable="d"
Title="{Binding Path=Content.Title, ElementName=_mainFrame}"
Height="450" Width="800"
WindowState="Maximized">
<Grid>
<DockPanel>
<Frame x:Name="_mainFrame" Source="Index.xaml" Margin="0,-8,0,8" />
</DockPanel>
</Grid>
</Window>
I'm aware some bits are left out because for some reason the editor wouldn't let me post it otherwise - but the important thing is the title binding anyway. Is this the wrong way to go about it? As title I get the project name and index.xaml, not the page title itself.
EDIT:
What I'm trying to achieve is that the window title (title of MainWindow.xaml) updates whenever a new page gets displayed in the frame. The window title should be the same as the page title.
In this article
the solution I'm currently using got presented, but it's not working as expected, displaying Projectname/URI-to-page rather than the page title as the window title.
Example:
Window title should be "your choice - the Mission" (as it is the page title) - in fact the window title is your_choice_1;compontent/Index.xaml

This Code is working fine for me: (I don't see an error in your Code...???)
Is your index.xaml of type Page or having a Title property?
<Window x:Class="WpfApp1.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:WpfApp1"
mc:Ignorable="d"
Title="{Binding Path=Content.Title, ElementName=MainFrame}" Height="450" Width="800">
<Grid>
<Frame x:Name="MainFrame" Source="Index.xaml">
</Frame>
</Grid>
</Window>
Index.xaml
<Page x:Class="WpfApp1.Index"
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:WpfApp1"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="Index Tester">
<Grid>
<TextBlock Text="Hallo"></TextBlock>
</Grid>
</Page>

Related

WPF MVVM - How can I pass two variables from the ViewModel associated with the first window to the second ViewModel associated with the second window?

I don't want to use Prism or MVVM Light solutions and would like to pass two parameters to the second window? How could I do that? I was looking for some information on this topic, but unfortunately most of them use packages...
try this:
App.xaml
<Application.Resources>
<vm:MainViewModel x:Key="YourViewModel" />
</Application.Resources>
MainWindow.xaml
<Window x:Class="ABC.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:ABC"
DataContext="{StaticResource YourViewModel}"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<TextBlock Text="{Binding SomeVar}"/>
</Grid>
</Window>
SecondWindow.xaml
<Window x:Class="ABC.SecondWindow"
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:ABC"
DataContext="{StaticResource YourViewModel}"
mc:Ignorable="d"
Title="SecondWindow" Height="450" Width="800">
<Grid>
<TextBox Text="{Binding SomeVar}"/>
</Grid>
</Window>
I guess you could just send parameters in the constructor of the second window, wherever you are creating your window.
var newwin = new SecondWindow("second param is int", 42 );
newwin.Show();
And then just create an another constructor for your window:
public SecondWindow(string a, int b) : this()
{
var secondVM = (SecondViewModel)DataContext;
secondVM.IAmSendingYouTwoParams( a,b);
...
}

Custom Window with all sides Grip

Recently I want to make a custom window with WPF for my program.
Here is the code of the Window:
<Window x:Class="Test.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:Test"
mc:Ignorable="d"
Title="Test" Height="450" Width="850" Background="Transparent" AllowsTransparency="True" WindowStartupLocation="CenterScreen" ResizeMode="CanResizeWithGrip" WindowStyle="None">
</Window>
I want to recreate a titlebar that I set the WindowStyle to None.
Now I need to resize the window with the grip. However, the Grip will not work anymore if I set the WindowStyle to None.
In spite I can set the ResizeMode to CanResizeWithGrip. Whereas, it only works on the bottom right side of the Window.
I want to make the Grip work all sides of the window. How can I achieve it?
You can set the ResizeBorderThickness property of a WindowChrome to make a custom window resizable:
<Window x:Class="WpfApp1.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"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" WindowStyle="None">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0" ResizeBorderThickness="5" />
</WindowChrome.WindowChrome>
<Grid Background="Yellow">
<TextBlock>Resizable window...</TextBlock>
</Grid>
</Window>

Can't open the main page XAML designer when open a new project

I'm just started using XAMl
so when i start a new project it shows this message in below
the only code was written is that
<Page
x:Class="App2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App2"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-
compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
</Grid>
</Page>

UserControl in windows phone 8.1 blank template

My requirement is masterpage in windows phone 8.1 blank template, i searched in the google, they suggest the usercontrol, i applied that scenario but not working,Below is my tried sample code.
`I'm try create Application where i required to use User Control.I'm already created MainPage.xaml here code below
`
<Page
x:Class="VtDesigning.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:VtDesigning"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
</Grid>
</Page>
and usercontrol defined below
<UserControl
x:Class="VtDesigning.MyUserControl2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:VtDesigning"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<StackPanel Height="50" Background="Chocolate">
<TextBlock Text="hi hellow how are you"
FontSize="25"
Margin="0,0,154,0"/>
</StackPanel>
</Grid>
</UserControl>
How to i call this usercontrol in MainPage.xaml.
Thanks,
Venky.
Set a reference to the location of the user control and add the user control to your layout as a normal control
<Page
x:Class="VtDesigning.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:VtDesigning"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:project="using:MyProject.UserControls"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<project:MyUserControl/>
</Grid>

Controls is not Supported in the Windows Presentation Foundation (WPF) Project

I am trying to use a user control and I have tried a few different solutions but, I have not been able to fix this issue:
In my main window, I have written code like below:
<Window x:Class="WPF_Work_Timer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPF_Work_Timer"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TabControl>
...
<TabItem Header="This Week">
<controls.WeekView></controls.WeekView>
<!-- ^Controls is not supported in WPF Error is here. -->
</TabItem>
...
</TabControl>
</Grid>
</Window>
I have written code like below for the User Control:
<UserControl x:Class="WPF_Work_Timer.WeekView"
x:Name="WeekViewControl"
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="300" d:DesignWidth="300">
<Grid>
...
</Grid>
</UserControl>
I have searched for a solution for this issue and I am sure that I am missing something very simple.
The problem is you're using a period . instead of a colon :. Try this:
<controls:WeekView></controls:WeekView>

Categories