请有人帮忙。下面是我不能编译的XAML代码
<Window x:Class="XAMLCalendar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:XAMLCalendar"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel Orientation = "Horizontal">
<!-- Create a Calendar that displays dates through
Januarary 31, 2015 and has dates that are not selectable. -->
<Calendar Margin = "20" SelectionMode = "MultipleRange"
IsTodayHighlighted = "false"
DisplayDate = "1/1/2015"
DisplayDateEnd = "1/31/2015"
SelectedDatesChanged = "Calendar_SelectedDatesChanged"
xmlns:sys = "clr-namespace:System;assembly =mscorlib">
<Calendar.BlackoutDates>
<CalendarDateRange Start = "1/2/2015" End = "1/4/2015"/>
<CalendarDateRange Start = "1/9/2015" End = "1/9/2015"/>
<CalendarDateRange Start = "1/16/2015" End = "1/16/2015"/>
<CalendarDateRange Start = "1/23/2015" End = "1/25/2015"/>
<CalendarDateRange Start = "1/30/2015" End = "1/30/2015"/>
</Calendar.BlackoutDates>
<Calendar.SelectedDates>
<sys:DateTime>1/5/2015</sys:DateTime>
<sys:DateTime>1/12/2015</sys:DateTime>
<sys:DateTime>1/14/2015</sys:DateTime>
<sys:DateTime>1/13/2015</sys:DateTime>
<sys:DateTime>1/15/2015</sys:DateTime>
<sys:DateTime>1/27/2015</sys:DateTime>
<sys:DateTime>4/2/2015</sys:DateTime>
</Calendar.SelectedDates>
</Calendar>
</StackPanel>
</Grid>
</Window>
下面是
背后的c#partial classusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace XAMLCalendar
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Calendar_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
{
var calendar = sender as Calendar;
// ... See if a date is selected.
if (calendar.SelectedDate.HasValue)
{
// ... Display SelectedDate in Title.
DateTime date = calendar.SelectedDate.Value;
this.Title = date.ToShortDateString();
}
}
}
}
以下是我收到的错误消息
严重级代码描述项目文件行抑制状态 错误未知构建错误,''clr-namespace:System; assembly = mscorlib'映射URI无效。 6号线位置9.' XAMLCalendar C:\ Users \ mypc \ documents \ visual studio 2017 \ Projects \ XAMLCalendar \ XAMLCalendar \ MainWindow.xaml第6行
严重级代码描述项目文件行抑制状态 错误URI“clr-namespace:System; assembly = mscorlib”不是有效的命名空间标识符。 XAMLCalendar C:\ Users \ mypc \ documents \ visual studio 2017 \ Projects \ XAMLCalendar \ XAMLCalendar \ MainWindow.xaml第20行
严重级代码描述项目文件行抑制状态 错误名称“DateTime”在名称空间“clr-namespace:System; assembly = mscorlib”中不存在。 XAMLCalendar C:\ Users \ mypc \ documents \ visual studio 2017 \ Projects \ XAMLCalendar \ XAMLCalendar \ MainWindow.xaml第31行
严重级代码描述项目文件行抑制状态 错误名称“DateTime”在名称空间“clr-namespace:System; assembly = mscorlib”中不存在。 XAMLCalendar C:\ Users \ mypc \ documents \ visual studio 2017 \ Projects \ XAMLCalendar \ XAMLCalendar \ MainWindow.xaml第32行
........与上面直接相同的错误,直到第37行
有人可以告诉我为什么它不会编译。我已经尝试将mscorlib引用添加到我的项目中,但它不会让我。说“构建系统已经自动引用了这个组件”
在上面的XAML中的Calender元素中,xmlns:sys下面还有一条蠕动线。当我将鼠标悬停在它上面时,intellisense说“URI”clr-namespace:System; assembly = mscorlib“不是有效的命名空间标识符
干杯。我正在使用Microsoft visual studio 2017社区
答案 0 :(得分:3)
只需删除名称空间声明中的额外空格。
<Window x:Class="XAMLCalendar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:XAMLCalendar"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel Orientation = "Horizontal">
<!-- Create a Calendar that displays dates through
Januarary 31, 2015 and has dates that are not selectable. -->
<Calendar Margin = "20" SelectionMode = "MultipleRange"
IsTodayHighlighted = "false"
DisplayDate = "1/1/2015"
DisplayDateEnd = "1/31/2015"
SelectedDatesChanged = "Calendar_SelectedDatesChanged"
xmlns:sys = "clr-namespace:System;assembly=mscorlib">
<Calendar.BlackoutDates>
<CalendarDateRange Start = "1/2/2015" End = "1/4/2015"/>
<CalendarDateRange Start = "1/9/2015" End = "1/9/2015"/>
<CalendarDateRange Start = "1/16/2015" End = "1/16/2015"/>
<CalendarDateRange Start = "1/23/2015" End = "1/25/2015"/>
<CalendarDateRange Start = "1/30/2015" End = "1/30/2015"/>
</Calendar.BlackoutDates>
<Calendar.SelectedDates>
<sys:DateTime>1/5/2015</sys:DateTime>
<sys:DateTime>1/12/2015</sys:DateTime>
<sys:DateTime>1/14/2015</sys:DateTime>
<sys:DateTime>1/13/2015</sys:DateTime>
<sys:DateTime>1/15/2015</sys:DateTime>
<sys:DateTime>1/27/2015</sys:DateTime>
<sys:DateTime>4/2/2015</sys:DateTime>
</Calendar.SelectedDates>
</Calendar>
</StackPanel>
</Grid>
</Window>