I want to set the title on an XAML page with an XAML Page container. There is no "Title" or "WindowTitle" tag for Page. However, when run, the VS project name, XAML_001, appears in the title area. How do I set my own title?
I have tried using what I know from C#/WPF which uses an XAML Window container which does have a "Title" tag. But, this does not work for a VS 2017 Blank App (C++/WinRT).
<Page
x:Class="XAML_001.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XAML_001"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="ClickHandler">Click You</Button>
</StackPanel>
</Page>
I cannot figure out how to change the title.
I found that the title which appears in the Windows Title Bar for the C++/WinRT, XAML application is set in the Package.appxmanifest file, “Application” tab in the “Display name” text box.
For reasons of which I am unaware, the "Title" property is not in the Windows.UI.Xaml.Controls Page Class as it is for C#, WPF applications.
Related
I am develop a new app for Windows 11 with WinUi 3 and in my MainPage the button appears all black in dark theme:
Why this happen?
This is a resume of my code:
<Window
<Grid Name="Main" RowDefinitions="Auto,*">
<RelativePanel Grid.Row="0"
Background="{ThemeResource SystemControlAcrylicWindowBrush}">
<TextBlock Name="TextBlock_AAA"
Text="AAA">
</RelativePanel>
<RelativePanel Grid.Row="1">
<Button Name="Button_AAA"
Content="AAA"
Click="AAA_Click"/>
</RelativePanel>
</Grid>
</Window>
#Luís, you're putting your UI directly in your window which is why it is not being styled.
Add a Blank Page (from the WinUI tab in VisualStudio) called something like "MainPage" and move your Grid into the XAML for the Page.
In the XAML for your main window, simply put <local:MainPage/> as the only content.
Now your button will look like the one in the comment by #nico-zhu-msft
I am creating a custom panel which is basically just a fancier StackPanel with some added functionality. I was going to use a UserControl which contains a StackPanel but I don't know how to make my UserControl accept content to fill it's StackPanel.
This is what I'm trying:
<UserControl
x:Class="transformations.fold_panel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:transformations"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Vertical">
<Button Content="First" />
<ContentControl Content="{x:Bind Content, Mode=OneWay}"></ContentControl>
</StackPanel>
</UserControl>
Usage:
<local:fold_panel>
<Button Content="Second" />
</local:fold_panel>
When I try this I get the following error:
WinRT originate error - 0x80070057 : 'The parameter is incorrect.'.
You can't bind the Content of a StackPanel in a UserControl's Content to the Content property of the same UserControl. This will introduce a circular reference.
In your example, the Content property of the fold_panel UserControl will be set to the StackPanel that you defined in the XAML markup.
If you want to be able to set the Content of the ContentControl in the StackPanel, you should add a custom dependency property to the fold_panel class and bind the Content property of the ContentControl to this one:
<ContentControl Content="{x:Bind CustomContent, Mode=OneWay}" />
You can then set your custom property something like this:
<local:fold_panel>
<local:fold_panel.CustomContent>
<Button Content="Second" />
<local:fold_panel.CustomContent>
</local:fold_panel>
But if you really want a custom StackPanel, you should create a class that inherits from StackPanel rather than UserControl.
It seems like every object that has been added to a page in a Windows 8 App gets this "slide from right to left"-entrance-transition which begins whenever someone navigates to the page.
Is there a possibility to remove single objects from this transition?
Neither
<Object.Transitions>
<TransitionCollection />
</Object.Transitions>
nor this thread helped...
Any ideas?
AFAIK There's no way to exempt a given object from the transitions applied by it's parents. The only thing I can suggest is to structure your xaml in such a way that the transition isn't applied. By this I mean having this special item in a panel that has no children transitions while the rest of the page is in a panel with a child transition. Depending on where this item is it could be very easy or difficult as hell.
As Nigel suggested, the only solution I have found has been to change the page structure and put the elements out of the grid that has the animations:
<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">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.Transitions>
<TransitionCollection/>
<!-- Ensure no transitions in background -->
</Grid.Transitions>
<TextBlock FontSize="50" Margin="50">This item is not animated</TextBlock>
<Grid>
<Grid.ChildrenTransitions>
<TransitionCollection>
<!-- add transitions here -->
<EntranceThemeTransition FromVerticalOffset="1500" FromHorizontalOffset="1500"/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<TextBlock Margin="50,100" FontSize="50">This item is animated</TextBlock>
</Grid>
<TextBlock FontSize="50" Margin="50,150">Another not animated item</TextBlock>
</Grid>
</Page>
Is there a way to change the background color for all pages? Or do I just have to change the LayoutRoot color on every page?
What you can do is create a Style that applies the Background Colour, you would still need to apply the style to each page, but afterwards if you need to make more changes you'll just need to alter the Style.
An example style applied to a page can be seen at Using Styles and Resources to simplify your xaml while this doesn't include background it should be easy enough to follow.
You could create a base page class and set the background color in that then inherit from the base page in all your other pages.
Edit
Base page code:
public class BasePage : PhoneApplicationPage
{
public BasePage()
{
Background = new SolidColorBrush(Colors.Red);
}
}
Main page xaml. Note the grid binds to the background color of the page.
<WindowsPhoneApplication2:BasePage
x:Class="WindowsPhoneApplication2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:WindowsPhoneApplication2="clr-namespace:WindowsPhoneApplication2"
mc:Ignorable="d"
d:DesignWidth="480"
d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape"
Orientation="Portrait"
shell:SystemTray.IsVisible="True"
x:Name="root">
<Grid
x:Name="LayoutRoot"
Background="{Binding Path=Background, ElementName=root}">
</Grid>
</WindowsPhoneApplication2:BasePage>
I have found a solution.
The issue is relying in how Mango defines the background color for pages.
The only way around it is to use application wide styles and apply it to the pages.
Here is a good howto: Windows Phone Mango Custom application Theme Step by Step
Following those suggestion I was even able to change the colors dynamically.
Adding following to the application resources sets color on all pages.
<Style TargetType="phone:PhoneApplicationFrame">
<Setter Property="Background" Value="{StaticResource SomeBrush}"/>
</Style>
i would like to create a custom base class for some of my UserControls.
Doing this in VS2008 is fine and compiles as expected, but when i edit the control in Blend 3 the base class in the blabla.g.vb is always changed back to System.Windows.Controls.UserControl.
How can i force Blend to keep the assigned base class?
regards
Christoph
Can you show your XAML?
I suspect the case is your XAML is like this:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SilverlightApplication15"
x:Class="SilverlightApplication15.MainPage"
Width="640"
Height="480">
<Grid x:Name="LayoutRoot"
Background="#FF313131" />
</UserControl>
When it should be something like:
<local:BlahBlah xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SilverlightApplication15"
x:Class="SilverlightApplication15.MainPage"
Width="640"
Height="480">
<Grid x:Name="LayoutRoot"
Background="#FF313131" />
</local:BlahBlah>
The .g.vb file is generated from the XAML so it's not a file you should edit directly.