XAML 以数字开头的命名空间

XAML Namespace Beginning with a Number

我继承了 Button 并正在尝试将其添加到我的主要 window。

它没有出现在 Toolbox 中。我试过几次重建。

我尝试将 xmlns:dc="clr-namespace:123Lettersxmlns:dc="clr-namespace:123Letters;assembly=123Letters 添加到我的 MainWindow

我的MainWindow是:

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Name="MainWin"
        Title="123 Letters">

</Window>

我的WeatherStationButton是:

<Button x:Class="WeatherStationButton"
        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>
</Button>

Public Class WeatherStationButton
    Inherits Button

    Public Property WeatherStation As tblWeather
End Class

这是非常简单的东西。我相信这是因为 XAML 不允许在命名空间的第一部分中使用数字,但我找不到任何对 anywhere 的引用,所以我问我是否正在做有什么问题或者这是 XAML 的 "features"?

刚刚意识到我可以添加我的答案。

如果您的项目名称是 123Letters,您需要在 XAML 中引用它时在第一个数字前添加下划线,例如 _123Letters.

您的 clr-namespace 声明将是:

xmlns:dc="clr-namespace:_123Letters"

您可以像这样将继承的按钮添加到主窗口:

<dc:WeatherStationButton x:Name="btnWS" />