C++/WinRT에서 UWP의 2Xam 편집

18961 단어 VC++WinRTC++
·MFC는 개발할 때 드래그 앤 드롭을 통해 다양한 제어를 구성할 수 있지만, UWP 앱은 Xaml을 편집해 다양한 제어를 구성한다.나는 그렇게 어려운 일을 할 생각이 없으니 안심하세요.
・아래 페이지를 참조하였습니다.감사합니다.
XAML의 기본(Xamarin 공식 XAML 페이지 전체 번역) 및 기본 포털
WPF Tips 컬렉션
XAML 시작 XAML 개요
기본적으로 상술한 내용을 참고하여 더욱 잘 썼다.
이른바 xaml
· MS의XAML 개요(선동)을 자세히 읽어주세요.
• C++/WinRT를 사용하는 입장에서 제어할 수 있는 설정, 제어할 수 있는 각종 속성, 이벤트 처리 프로그램의 설정, 귀속된 설정 등에 사용되는 언어이다.기본적으로 xml이기 때문에 탭으로 외관과 이벤트 처리 프로그램을 편집하는 것이 필요하다고 생각하면 문제 없겠죠?VS의 인텔리코드가 우수하기 때문에 현지에서 속성 등을 추가하기 어렵다.

1. 어떤 외관을 만들까


・ 아래 그림과 같은 외관을 가진 프로그램을 만듭니다.

・화면을 두 부분으로 나누어 왼쪽으로 버튼을 정렬하고 오른쪽으로 TextBox를 정렬한다.버튼은 가운데에 있고 TextBox의 상단 정렬 여백은 10입니다.

2. 프로젝트 제작


· 지난번과 마찬가지로 블랙앱(C++/WinRT)을 선택해 이번에'xaml 1'이라는 이름으로 프로젝트를 제작한다.

3. 방해되는 버튼 삭제


・MainPage.xaml을 선택하고 delete 키로 삭제합니다.이런 느낌.
MainPage.xaml(편집 전)
<Page
    x:Class="BlankApp1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BlankApp1"
    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 Me</Button>
    </StackPanel>
</Page>
MainPage.xaml(편집 후)
<Page
    x:Class="BlankApp1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BlankApp1"
    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">

    </StackPanel>
</Page>
· 프로세서의 MainPage를 기술했습니다.cpp도 CliclHandler를 제거하십시오.
아, 깜빡했네, MainPage.h에서도 지워주세요.
MainPage.cpp(편집 전)
#include "pch.h"
#include "MainPage.h"
#include "MainPage.g.cpp"

using namespace winrt;
using namespace Windows::UI::Xaml;

namespace winrt::BlankApp1::implementation
{
    MainPage::MainPage()
    {
        InitializeComponent();
    }

    int32_t MainPage::MyProperty()
    {
        throw hresult_not_implemented();
    }

    void MainPage::MyProperty(int32_t /* value */)
    {
        throw hresult_not_implemented();
    }

    void MainPage::ClickHandler(IInspectable const&, RoutedEventArgs const&)
    {
        myButton().Content(box_value(L"Clicked"));
    }
}
MainPage.cpp(편집 후)
#include "pch.h"
#include "MainPage.h"
#include "MainPage.g.cpp"

using namespace winrt;
using namespace Windows::UI::Xaml;

namespace winrt::BlankApp1::implementation
{
    MainPage::MainPage()
    {
        InitializeComponent();
    }

    int32_t MainPage::MyProperty()
    {
        throw hresult_not_implemented();
    }

    void MainPage::MyProperty(int32_t /* value */)
    {
        throw hresult_not_implemented();
    }
}
・이렇게 구축하면 방해가 되는 버튼이 사라집니다.다음은 정식 공연이다.

4.MainPage.편집xaml


・Mainpage.xaml를 다음과 같은 내용으로 바꾸기
MainPage.xaml
<Page
    x:Class="BlankApp1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BlankApp1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="0">
            <Button x:Name="button1" Width="300" Height="75" Content="Button1" FontSize="24" Background="Tomato"/>
            <Button x:Name="button2" Width="250" Height="75" Content="Button2" Margin="0,10,0,0" HorizontalAlignment="Center" Background="YellowGreen" >
                <Button.BorderBrush>
                    <SolidColorBrush Color="{ThemeResource SystemColorBackgroundColor}"/>
                </Button.BorderBrush>
            </Button>
        </StackPanel>

        <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Column="1">
            <TextBox x:Name="textBox1" Height="300" Width="500" Background="Tomato" ></TextBox>
            <TextBox x:Name="textBox2" Height="400" Width="500" Margin="0,10,0,0" Background="YellowGreen" ></TextBox>
        </StackPanel>
    </Grid>
</Page>
· "Buton"에 Click="를 추가하면 아래와 같이"새 이벤트 처리기"를 추가하고 나타나면"새 이벤트 처리기"를 클릭합니다.이벤트 프로세서를 추가하십시오.button2에도 추가해주세요.

・MainPage.cpp에 "button1 Click"과 "button2 Click"의 활성 프로세서가 추가되어야 합니다.확인 후 간단하게xaml에 들어가는 설명입니다.
『 Grid 』: 이번에는 화면을 두 부분으로 나누기 위해 사용하였습니다.
・《Grid》.화면을 의 수에 따라 가로로 분할합니다.이번에는 두 번이어서 가로로 두 부분으로 나뉜다.이번에는 사용하지 않았지만, ・『StackPanel〉: 구성이 복잡할 때는 사용하지 않지만 이번에는 나란히 표시되기 때문에 사용합니다.각 컨트롤이 Margin을 잊어버리면 뒤에 숨어 있음을 주의하십시오.
나중에 많이 이해해 주세요.xaml 편집에서도 인텔리코드에 다양한 기능이 표시되는데, 잘 모르더라도 다양한 기능을 추가할 수 있을 것으로 보인다.

5.MainPage.cpp 편집 및 구축, 실행


・MainPage.cpp의 이벤트 처리 프로그램에 다음과 같은 내용을 추가합니다.코드량이 적어서 다 올려놨어요.
MainPage.cpp
#include "pch.h"
#include "MainPage.h"
#include "MainPage.g.cpp"

using namespace winrt;
using namespace Windows::UI::Xaml;

namespace winrt::BlankApp1::implementation
{
    MainPage::MainPage()
    {
        InitializeComponent();
    }

    int32_t MainPage::MyProperty()
    {
        throw hresult_not_implemented();
    }

    void MainPage::MyProperty(int32_t /* value */)
    {
        throw hresult_not_implemented();
    }

}


void winrt::BlankApp1::implementation::MainPage::button1_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e)
{
    //追加
    textBox1().Text(L"Hello xaml textBox1");
}


void winrt::BlankApp1::implementation::MainPage::button2_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e)
{
    //追加
    textBox2().Text(L"Hello xaml textBox2");
}
• 구문을 실행한 후 버튼을 클릭하면 다음과 같이 성공합니다.

· 제목을 변경했습니다. 이것은 Package입니다.appxmanifest → 응용 프로그램 → 디스플레이 이름에서 변경할 수 있습니다.
이놈도 지혁이 풀어줬어.
yoshiyoshi-git/xaml_1
다음은데이터 바인딩 1.이 점에서부터 C#에 비해서 귀찮아졌어요.
문자 방향

좋은 웹페이지 즐겨찾기