C# WPF UserControl based on Uniformgrid - c#

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.

Related

How to split wpf xaml page into more maintainable small parts

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/

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>

Silverlight XAML file error: The member "Margin" is not recognized or is not accessible

I have a reference to a silverlight xaml file in my project. When i try to build this project it throws following error
The member "Margin" is not recognized or is not accessible.
Here is my code:
<UserControl x:Class="DBServer.Selenium.Silvernium.ReferenceApplication.SilverlightFixture"
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:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<navigation:Frame x:Name="frameContent" Source="/MainPage.xaml" Margin="0,0,0,0"/>
</UserControl>
Have you tried to put the frame inside a grid?
<Grid>
<navigation:Frame x:Name="frameContent" Source="/MainPage.xaml" Margin="0,0,0,0"/>
</Grid>
because you are saying Margin="0,0,0,0" but in the XAML you don't have any other content as reference to the that distance defined in the Margin,so try or by removing the Margin or putting inside a grid

hide control while resizing window in wpf

I'm trying to hide a control during a window resize because it's not behaving right otherwise. However in WPF there doesn't seem to be any OnBeginResize-ish event.
Any suggestions how to achieve this in WPF?
Bind a property(Notifiable) to your window width so when the width changes Setter of this property will be invoked and within this setter you can have the logic to hide your control.
<Window x:Class="SiemensEnergy.Frw.Main.Client.UI.Views.MainWindowView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewmodel="clr-namespace:SiemensEnergy.Frw.Main.Client.UI.ViewModels"
Title="MainWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Width="{Binding WindowWidthProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
</Window>
Window_SizeChanged?
<Window x:Class="TestControls.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:WFControls;assembly=WFControls"
xmlns:ff="clr-namespace:WFControls.Fernfracht;assembly=WFControls"
Title="MainWindow" Height="350" Width="525" SizeChanged="Window_SizeChanged">
<DockPanel>
</DockPanel>
</Window>

Categories