0
所以我做出這個樣子的自定義面板:如何在頁面XAML中爲UWP添加自定義面板?
public class CustomPanel : Panel
{
protected override Size MeasureOverride(Size constraint)
{
...
}
protected override Size ArrangeOverride(Size arrangeSize)
{
...
}
}
在項目中,我有一個文件CustomPanel.cs。 現在我希望能夠把這個自定義面板在我的MainPage.xaml中,像這樣:
<Page x:Class="CustomPanelProject.Views.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CustomPanelProject.Views"
xmlns:control="using:CustomPanelProject.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
Orientation="Vertical">
<control:CustomPanel>
</control:CustomPanel>
</StackPanel>
因此,我認爲這種做法將工作,但設計師繼續顯示此錯誤消息:
命名空間「using:CustomPanelProject.Controls」中不存在名稱「CustomPanel」。
我錯過了什麼?也許面板應該有一個像用戶控件一樣的相關xaml文件?
你確定你的CustomPanel類實際上是在'CustomPanelProject.Controls'命名空間中聲明的嗎? – Clemens
設計師抱怨這個面板的事實並不總是意味着它有什麼問題。您是否嘗試構建或運行您的項目?有時需要讓設計師更清爽。 –