2012-04-22 55 views
0

我需要在我的WPF應用程序中使用datepicker控件,但我無法在Toolbox中找到此控件。然後,我安裝WPFToolKit並在xaml文件代碼中添加名稱空間,但仍顯示以下錯誤:
錯誤1標記'DatePicker'不存在於XML名稱空間中'http://schemas.microsoft.com/winfx/2006/XAML /演示」。第23行18位F:\穆罕默德ANEES \ codereason_reports_v0.5_alpha \的Samples \ SimpleReport \ EmployeeManager.xaml 23 18 Employee_Manager
DatePicker控制錯誤

這裏是我的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> 

DatePicker控件在上面代碼中的第二個Radiobutton控件之後。 請告訴我如何解決這個問題。 感謝

回答

1

我認爲你正在使用WPF工具包,你需要使用的工具包,你已經指定了在開始爲WPF工具大會

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

謝謝它工作! 還有一件事,我想禁用這個datepicker控件,我該怎麼做?我這樣做:datepicker1.IsEnabled = false,但它不會工作! – Azeem 2012-04-22 16:16:27

1

如果這是從的NuGet的WPF工具包,那麼你叫它像:

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

你也可能必須嘗試和清潔,構建解決方案事業之前,使用該工具包實際上我得到這個錯誤,但它的工作後,我重建瞭解決方案。

+0

謝謝它工作!還有一件事,我想禁用這個日期選擇器控件,我該怎麼做?我這樣做:datepicker1.IsEnabled = false,但它不會工作! – Azeem 2012-04-22 16:29:34

+0

它應該只是控件中的一個屬性,您應該只需說:IsEnabled = false沒有datepicker1。 – TMan 2012-04-22 18:08:11

+0

所以在xaml中,說:IsEnabled =「false」。如果你想切換isenabled,那麼你可以在代碼後面創建一個屬性,並將該屬性綁定到IsEnabled,以便ex/IsEnabled =「{Binding EnabledOrNot}」 – TMan 2012-04-22 18:11:26