我正在为WPF使用Telerik RAD控件的WPF应用程序。该应用程序将在具有触摸屏的PC上使用,因此我需要使DateTimePicker控件上的拾取器变得更大,以便像我自己的香肠手指一样可以轻松地按下它们。应用程序无法在Generic.xaml中找到资源
我最初使用Expression Blend编辑控件模板的副本。这在我设计的UserControl的XAML文件中创建了一个ControlTemplate。我有另一个用户控件,我现在正在使用它也将使用DateTimePicker,所以我想重新使用ControlTemplate。
我所做的是将修改的模板移动到项目(WPF控件库)Generic.XAML中的新命名样式中。这里的Generic.xaml的一小段:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CarSystem.CustomControls"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:Telerik_Windows_Controls_Chromes="clr-namespace:Telerik.Windows.Controls.Chromes;assembly=Telerik.Windows.Controls">
<Style x:Key="RadDateTimePickerControlTemplate1" TargetType="{x:Type telerik:RadDateTimePicker}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type telerik:RadDateTimePicker}">
. . .
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
这里是XAML的一个片段,我引用的样式:
<UserControl x:Class="CarSystem.CustomControls.ReportCriteria"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:cs="clr-namespace:CarSystem.CustomControls"
mc:Ignorable="d"
Height="648"
Width="1117">
<Grid Background="{DynamicResource ContentBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GroupBox BorderBrush="Black" FontSize="20" FontWeight="Bold" Grid.Row="0" Header="Report Criteria: " Margin="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="320" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="450" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="110" />
</Grid.ColumnDefinitions>
<GroupBox BorderBrush="Black" FontSize="20" FontWeight="Bold" Grid.Column="0" Header="Date Range:" Margin="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock FontSize="18"
FontWeight="Bold"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Right"
Text="Start Date: " />
<telerik:RadDateTimePicker FontSize="18"
FontWeight="Bold"
Grid.Column="1"
Grid.Row="0"
Name="StartDatePicker"
Style="{DynamicResource RadDateTimePickerControlTemplate1}" />
<TextBlock FontSize="18"
FontWeight="Bold"
Grid.Column="0"
Grid.Row="1"
HorizontalAlignment="Right"
Text="End Date: " />
<telerik:RadDateTimePicker FontSize="18"
FontWeight="Bold"
Grid.Column="1"
Grid.Row="1"
Name="EndDatePicker"
Style="{DynamicResource RadDateTimePickerControlTemplate1}" />
</Grid>
</GroupBox>
. . .
</GroupBox>
</Grid>
</UserControl>
当我在Expression Blend工作,一切都看起来不错。我看到控件下拉按钮宽度的变化。回到Visual Studio,所有的东西都编译得很好,但是这个变化并没有显示出来 - 我只看到了控件的默认样式,而且样式的引用在它们下面有一条蓝色的波浪线。当你将鼠标悬停在波浪线,显示以下信息:如果我在XAML改变“DynamicResource”到“静态资源”
The resource "RadDateTimePickerControlTemplate1" cannot be resolved.
同样的事情发生。另外,我没有对该项目的Assembly.Info文件进行更改。
我该如何解决这个问题?
感谢
托尼
是在主题文件夹中的generic.xaml您的项目?该项目真的是WPF库吗?并且这个lib是作为参考添加到您的项目中的吗? 或者是你的应用程序中的generic.xaml?您可以尝试通过ResourceDictionary在您的usercontrol资源中引用您的generic.xaml。 – dowhilefor
是的,它位于项目的主题文件夹中。这真是一个WPF库。是的,它被添加为我的项目中的参考。该库中有很多UserControls和一些CustomControls,它们在项目的其他地方使用。相同的Generic.xaml文件具有应用程序中所有CustomControls的默认控制模板,并且工作正常。你能举一个例子说明你的“在你的usercontrol资源视图ResourceDictionary中引用你的generic.xaml”是什么意思? –