【问题标题】:Why can't I insert a Calendar or a date time picker in WPF?为什么我不能在 WPF 中插入日历或日期时间选择器?
【发布时间】:2013-09-17 13:25:37
【问题描述】:

我试图通过插入日历标签在 WPF 应用程序中插入日历,但出现此错误?

找不到类型“日历”。确认您没有丢失程序集引用并且所有引用的程序集都已构建 这是代码:-

<Window x:Class="HomeExpenseCalculator.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Window1" Height="395.516" Width="445.511">
    <Grid>
        <Label Height="25" Name="label1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="88" FontSize="14" Margin="14,15,0,0" Background="White">Person</Label>
        <ComboBox Height="23" Margin="159.984,15,95.546,0" Name="comboBox1" VerticalAlignment="Top">
            <ComboBoxItem>Pankaj</ComboBoxItem>
            <ComboBoxItem>Shad</ComboBoxItem>
            <ComboBoxItem>Kartik</ComboBoxItem>
            <ComboBoxItem>Abhinav</ComboBoxItem>
            <ComboBoxItem>Rahul</ComboBoxItem>
        </ComboBox>
        <Label Height="28" Margin="3,63.327,0,0" Name="label2" VerticalAlignment="Top"   HorizontalAlignment="Left" Width="99" FontSize="12" Background="White">Stuff   Purchased</Label>
        <TextBox Height="63" Margin="111,48,38,0" Name="textBox1" VerticalAlignment="Top" />
        <Calendar> </Calendar>
    </Grid>
</Window>

【问题讨论】:

  • 向我们展示代码:)(您是否尝试过使用大写“C”的日历?)
  • 我已经添加了上面的代码
  • 您的目标是哪个版本的 .NET Framework?
  • 它是 3.5 版(VS 2008)
  • 那么您就不能使用 Calendar 和 DatePicker - 它们已包含在 .NET 4 的 WPF 中。

标签: c# .net wpf wpf-controls


【解决方案1】:

我创建了一个新窗口并添加了日历控件,没有出现任何错误。下面是 XAML 的样子:

<Window x:Class="StackOverflow.TestWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="TestWindow" Height="300" Width="300">
    <Grid>
        <Calendar />
    </Grid>
</Window>

【讨论】:

  • 我已经发布了上面的代码。请看一下。日历标签不起作用...
  • 我完全复制了您的代码,并将其粘贴到测试项目中,完全没有问题。
  • 也许尝试重新启动 Visual Studio。除了我不确定可能出了什么问题之外,代码看起来还不错。除非它像其他人所说的那样,并且您缺少程序集引用(默认情况下应该已经包含)。
  • 我的给出了两个错误 错误 1 ​​XML 命名空间“schemas.microsoft.com/winfx/2006/xaml/presentation”中不存在标签“日历”。第 16 行位置 10 2 未找到类型“日历”。确认您没有丢失程序集引用并且所有引用的程序集都已构建。
  • 这是一个 WPF 应用程序吗?或者您是在向 WinForms 应用程序添加 WPF 窗口吗?
【解决方案2】:

请在您的问题中更详细。

此错误表示您没有正确的程序集。

见:WPF assembly reference missing - project still building

【讨论】:

    【解决方案3】:

    也许您在 XAML 中没有对正确命名空间的引用? (即 xmlns=...)。

    您需要引用日历控件所在的命名空间才能使其工作...

    【讨论】:

    【解决方案4】:

    使用Calendar 而不是“日历”

    【讨论】:

    • 错误 1 ​​XML 命名空间“schemas.microsoft.com/winfx/2006/xaml/presentation”中不存在标记“日历”。第 16 行位置 10.C:\Documents and Settings\Shad\My Documents\Visual Studio 2008\Projects\HomeExpenseCalculator\HomeExpenseCalculator\Window1.xaml 16 10 HomeExpenseCalculator
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    • 2016-02-08
    相关资源
    最近更新 更多