When i set Build Action
of BaseResources.xaml
to Page
and it will work.
When i set Build Action of BaseResources.xaml
to Resource
,I get the following error.
System.Windows.Markup.XamlParseException: ''Failed to create a 'Type' from the text 'xctk:DateTimePicker'.' Line number '4' and line position '40'.'
XamlParseException: Type reference cannot find type named '{http://schemas.xceed.com/wpf/xaml/toolkit}DateTimePicker'.
I've looked here, but i don't know how to get it to work when the Build Action
is set to Resource
.
This page states (note the word "must"):
Your resource must be defined as part of the project as a Resource build action.
So, why does "Page" work? Am I using the wrong reference link?
The following is my project.
Project structure:
BaseResources.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" >
<Style x:Key="DateTimePickerBase" TargetType="{x:Type xctk:DateTimePicker}">
<Setter Property="Background" Value="LightYellow" />
</Style>
</ResourceDictionary>
App.xaml:
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PIM"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
StartupUri="/Views/MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/PIM;component/Models/BaseResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
MainWindow.xaml:
<Window x:Class="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:self="clr-namespace:PIM"
mc:Ignorable="d"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<self:MainWindowVM/>
</Window.DataContext>
<StackPanel>
<TextBox Text="{Binding MyTextProperty}"/>
<xctk:DateTimePicker x:Name="dtp" Value="{Binding TodayDate}" Style="{StaticResource DateTimePickerBase}"></xctk:DateTimePicker>
</StackPanel>
</Window>
MainWindowVM.vb:
Imports System.ComponentModel
Public Class MainWindowVM Implements INotifyPropertyChanged
Public Sub New()
Me.myTextValue = "default value..."
End Sub
Private myTextValue As String = String.Empty
Public Property MyTextProperty() As String
Get
Return Me.myTextValue
End Get
Set(ByVal value As String)
Me.myTextValue = value
NotifyPropertyChanged("MyTextProperty")
End Set
End Property
Private _todayDate As DateTime = DateTime.Today
Public Property TodayDate() As DateTime
Get
Return Me._todayDate
End Get
Set(ByVal value As DateTime)
Me._todayDate = value
NotifyPropertyChanged("TodayDate")
End Set
End Property
Public Event PropertyChanged As PropertyChangedEventHandler _
Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(ByVal propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class