日期选取器控件错误

本文关键字:错误 控件 选取 日期 | 更新日期: 2023-09-27 18:31:58

我需要在我的WPF应用程序中使用日期选取器控件,但在工具箱中找不到这个控件。然后我安装了 WPFToolKit 并在 xaml 文件代码中添加了命名空间,但它仍然显示以下错误:
错误 1 标记"日期选取器"在 XML 命名空间"http://schemas.microsoft.com/winfx/2006/xaml/presentation"中不存在。第 23 行位置 18。 F:''Muhammad Anees''codereason_reports_v0.5_alpha''Samples''SimpleReport''EmployeeManager.xaml 23 18 Employee_Manager

这是我的 xaml 文件代码:

<Window x:Class="SimpleReport.EmployeeManager"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
Title="Employee Manager - Islam Engineering Pvt Ltd." Height="513" Width="865" ResizeMode="CanMinimize">
    <TabControl Height="482" HorizontalAlignment="Left" Margin="0,-2,0,0" Name="tabControl1" VerticalAlignment="Top" Width="832">
        <TabItem Header="Add New Employee" Name="tabItem1">
            <Grid Width="806" Height="440">
                <TextBox Height="23" HorizontalAlignment="Left" Margin="177,14,0,0" Name="txtBarcode" VerticalAlignment="Top" Width="120" Background="#FFE0DECC" KeyUp="txtBarcode_KeyUp" />
                <Label Content="Employee ID:" Height="28" HorizontalAlignment="Left" Margin="19,14,0,0" Name="label1" VerticalAlignment="Top" Width="85" />
                <TextBox Height="23" HorizontalAlignment="Left" Margin="177,49,0,0" Name="emp_name" VerticalAlignment="Top" Width="254" IsEnabled="True" />
                <Label Content="Employee Name:" Height="28" Margin="19,0,676,365" Name="label2" VerticalAlignment="Bottom" />
                <Button Content="Add" Height="23" Name="addbtn" Width="75" Background="#FFD0B8B8" BorderBrush="#FFB19414" Margin="176,136,554,281" Click="addbtn_Click" />
                <Label Height="28" HorizontalAlignment="Left" Margin="177,78,0,0" Name="addmsg" VerticalAlignment="Top" Width="275" Content="Employee added Successfully!" />
            </Grid>
        </TabItem>
        <TabItem Header="Employee Attendance Report" Name="tabItem2">
            <Grid>
                <Label Content="Select Report Type:" Height="28" HorizontalAlignment="Left" Margin="24,26,0,0" Name="label7" VerticalAlignment="Top" Width="122" />
            <Button Background="#FFD0B8B8" BorderBrush="#FFB19414" Content="Generate Report" Height="23" Margin="152,157,557,270" Name="reportBtn" Click="button1_Click" />
            <RadioButton Content="Today's Report" Height="16" HorizontalAlignment="Left" Margin="152,31,0,0" Name="radioButton1" VerticalAlignment="Top" />
            <DatePicker Height="25" HorizontalAlignment="Left" Margin="42,26,0,0" Name="datePicker1" VerticalAlignment="Top" Width="115" />
            <RadioButton Content="Previous Date" Height="16" HorizontalAlignment="Left" Margin="152,62,0,0" Name="radioButton2" VerticalAlignment="Top" />
            <RadioButton Content="Within Range" Height="16" HorizontalAlignment="Left" Margin="152,95,0,0" Name="radioButton3" VerticalAlignment="Top" />
        </Grid>
        </TabItem>
        <TabItem Header="Remove Employee Record" Name="tabItem3">
            <Grid>
                <ComboBox Height="23" HorizontalAlignment="Left" Margin="181,26,0,0" Name="comboBox3" VerticalAlignment="Top" Width="120" SelectionChanged="comboBox3_SelectionChanged" SelectedIndex="0" />
                <Label Content="Select Employee ID:" Height="28" HorizontalAlignment="Left" Margin="29,26,0,0" Name="label5" VerticalAlignment="Top" Width="122" />
                <Button Background="#FFD0B8B8" BorderBrush="#FFB19414" Content="Remove" Height="23" Margin="181,80,566,347" Name="button2" Width="75" />
            </Grid>
        </TabItem>
    </TabControl>

日期选取器控件在上面的代码中位于第二个单选按钮控件之后。请告诉我如何克服这个问题。谢谢

日期选取器控件错误

我认为您正在使用 WPF 工具包,您需要使用工具包,因为您在 WPF 工具包程序集的启动中指定了工具包

<toolkit:DatePicker Height="25" HorizontalAlignment="Left" Margin="42,26,0,0" Name="datePicker1" VerticalAlignment="Top" Width="115" />

如果这是来自 nuget 的 wpf 工具包,那么您可以这样称呼它:

 <toolkit:DatePicker Name="blah blah" Margin="0" ect.. > </toolkit:DatePicker>

您可能还必须尝试清理并构建解决方案,因为我在使用工具包之前实际上遇到了此错误,但在我重建解决方案后它起作用了。