【问题标题】:XAML Namespace Beginning with a Number以数字开头的 XAML 命名空间
【发布时间】:2015-01-07 22:45:39
【问题描述】:

我继承了Button 并尝试将其添加到我的主窗口中。

它不会出现在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 的“特性”?

【问题讨论】:

  • 我是对的。 XAML 对以数字开头的命名空间进行了秘密魔法。您必须在第一个数字前添加下划线,例如:_123Letters。除了反复试验之外,我没有其他参考资料。

标签: wpf vb.net xaml namespaces


【解决方案1】:

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

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

您的clr-namespace 声明将是:

xmlns:dc="clr-namespace:_123Letters"

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

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

【讨论】:

    猜你喜欢
    • 2016-02-25
    • 1970-01-01
    • 2015-04-28
    • 2016-02-11
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-01
    相关资源
    最近更新 更多