Dmitrii Kurylev Dmitrii Kurylev -4 years ago 161
C# Question

how I create xaml if i already have cs without xaml

I already have class C#

.cs
without
.xaml
page. Now I want to use
xaml
style in it. Can I create new
xaml
page and assign this with my written
.cs
class? Or I can delete my class and create new
xaml
with empty
cs
? I use Visual Studio 15 C#.

Answer Source

Make the x:class name the same as the class name. Make sure they are in the same namespace or reference the same namespaces.

This code works and the XAML / Class was created separately of one another.

Might wanna add 'InitializeComponent();' to the class constructor also but this works as is.

<Page
x:Class="Class_with_XAML_seperate.TestView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Class_with_XAML_seperate"
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>
</Page>


using Windows.UI.Popups;

namespace Class_with_XAML_seperate
{
    public partial class TestView 
    {
        public TestView()
        {
            new MessageDialog("Hello World").ShowAsync();
        }
    }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download