I'm creating a wpf application and the main page consist of a sidebar a header and a content area where the rest of the app will be displayed, since i come for an angular background can i split the sidebar and the header and the content area into small maintainable components and how can it be achieved
In your Solution Explorer, right click on your project and add a new UserControl. Call it for example "FeatureView". In that UserControl, insert a textblock with a dummy text like:
<UserControl x:Class="WpfApp10.FeatureView"
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:WpfApp10"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TextBlock Text="This is my FeatureView UserControl"/>
</Grid>
Then, in your MainWindow load it in the following way:
<Window x:Class="WpfApp10.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:WpfApp10"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<local:FeatureView/>
</Grid>
You should be able to see your dummy text. You can expand this with more UserControls.
You can split the areas into user controls:
https://learn.microsoft.com/en-us/visualstudio/extensibility/adding-user-control-to-the-start-page?view=vs-2017
A nice way of managing this is to use Prism Regions, see:
https://rohiton.wordpress.com/2016/06/08/understanding-prism-part-2-regions/
Related
If i have this code, how can i indicate to the TextBlock in HandyControl Window to use the default WPF Style and not the HandyControl one ?
Thanks in advance ! :)
<hc:Window
x:Class="TextTrimming_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:TextTrimming_Test"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Background="#181818">
<TextBlock Text="I want to be the default WPF TextBlock !"/>
</hc:Window>
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>
I'm trying to make the user control on the basis of UniformGrid. When using office error appears: The property 'Content' is set more than once
AdaptiveLayout.xaml
<UserControl x:Class="App.Controls.AdaptiveLayout"
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:element="clr-namespace:App.Controls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UniformGrid SizeChanged="UniformGrid_SizeChanged">
<ContentPresenter></ContentPresenter>
</UniformGrid>
</UserControl>
MainWindow.xaml
...
<controls:AdaptiveLayout TransferringAfter="190">
<controls:TextBoxWrapControl LabelContent="FirstName"></controls:TextBoxWrapControl>
<controls:TextBoxWrapControl LabelContent="LastName"></controls:TextBoxWrapControl>
</controls:AdaptiveLayout>
...
You are using a UniformGrid in your UserControl, but that does not actually make it into one. That's why it's complaining in your MainWindow.xaml that you set more than one content for your AdaptiveLayout.
You could try extending UniformGrid instead of using it.
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>
I create a window in wpf and in xml file I write this code:
<Window x:Class="WPFTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid >
</Grid>
</Window>
But when I run the project, the size of window is 1080*625. I expect the window size become the screen size, but isn't. Why?
You need to set WindowState to Maximmized:
<Window x:Class="WPFTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" WindowState="Maximized"/>