我正在尝试进行简单的页面导航,但无法找到有关如何在 WinUI 3.0 中执行此操作的任何文档。
目前,当我使用 WinUI 3.0 创建空白应用程序时,我在 App.xaml.cs 中创建了以下代码
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Activate();
}
private Window m_window;
Run Code Online (Sandbox Code Playgroud)
虽然我在网上找到了许多其他示例,但根框架是在上面的 OnLaunched 事件中定义的。
我如何定义 MainWindow.xaml 或 App.xaml,以便获得一个可以在 Page1.xaml 和 Page2.xaml 之间自由切换的框架?
编辑:我现在发现我可以通过调用来检索框架:
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
Frame rootFrame = m_window.Content as Frame;
m_window.Activate();
rootFrame.Navigate(typeof(UI.MainMenu));
}
Run Code Online (Sandbox Code Playgroud)
但导航失败并出现System.NullReferenceException: 'Object reference not set to an instance of an object.'错误。我做错了什么:S?
所以,我一直在为此苦苦挣扎。我有一个简单的函数,定义如下:
const unsigned char GetColor(unsigned int x, unsigned int y)
{
const unsigned char color[3] = {0, 1, 0};
return color;
}
Run Code Online (Sandbox Code Playgroud)
但是,不允许这样做,编译器将返回以下错误:
Error: cannot initialize return object of type 'const unsigned char' with an lvalue of type 'const unsigned char [3]'
Run Code Online (Sandbox Code Playgroud)
我应该将数组转换为指向数组的指针,应该返回该指针吗?如果这样做,我是否冒着在“超出范围”后又将其删除的风险?
在理解这个问题的任何帮助将不胜感激:)
编辑:最终目标是拥有一个函数,该函数可以在给定x和y值的情况下在像素位置返回颜色。这意味着颜色会根据x-和y的值而变化。上面的示例是一个简化。
它应返回大小为3的const无符号char数组,每个数组中都有一个值。
所以,我在代码中发现了一个相当奇怪的错误,我很难理解。我有一个 std::map 用于存储一些信息。当我第一次循环时,一切看起来都很好,但是第二次,数据丢失了。
首先,我使用一个结构体和一个类,如下所示:
struct Eng::Pixel{
unsigned int x;
unsigned int y;
};
class Eng::Edge{
public:
enum EdgeType { INTER, INTRA};
EdgeType type;
}
class Eng::Cluster{
public:
std::map<Pixel, std::vector<Edge>> trans;
}
Run Code Online (Sandbox Code Playgroud)
基本上,一个簇包含一张像素图。该地图中的每个像素都包含称为边缘的过渡点。每个像素可以有多个边缘 - 边缘可以是 inter(0) 或 intra (1) 类型。请注意,某些命名空间可能会丢失,因为我试图尽可能地简化我的问题。
当我循环代码时:
std::vector<Cluster> resClusters = this->GenerateClusters();
for(Cluster cluster : resClusters) //For a given cluster in clusters
{
this->CreateIntraEdges(cluster); //Create our intra edges. Succeeds.
std::cout << "Cluster: " << cluster << std::endl; //Prints the bounds of the cluster.
std::cout << "Cluster has " …Run Code Online (Sandbox Code Playgroud) 因此,对于最近尝试重载<<运算符时遇到的错误,我有一个疑问。
我有一个名为“ structPixels.h”的文件,在其中我定义了一个结构,如下所示:
#pragma once
#include <iostream>
namespace Eng
{
/**
* A structure to represent pixels
*/
typedef struct Pixel{
unsigned int x; ///The x-coordinate
unsigned int y; ///The y-coordinate
bool operator ==(const Pixel& rhs) const
{
return (this->x == rhs.x && this->y == rhs.y);
};
bool operator !=(const Pixel& rhs) const
{
return (this->x != rhs.x || this->y != rhs.y);
};
bool operator <(const Pixel& rhs) const
{
return std::tie(this->x, this->y) < std::tie(rhs.x, rhs.y);
}
friend std::ostream& operator …Run Code Online (Sandbox Code Playgroud)