2

I am working on a WPF application that uses the Telerik RAD controls for WPF. The application will be used on a PC with a touch screen, so I need to make things like pickers on the DateTimePicker control larger so they can be easily pressed by people with sausage fingers like my own.

I originally used Expression Blend to edit a copy of the control's template. That created a ControlTemplate in the UserControl's XAML file that I was designing. I have another UserControl I'm working on now that will also use the DateTimePicker, so I want to reuse the ControlTemplate.

What I did was I moved the modified template into a new named Style in the project's (a WPF Control Library) Generic.XAML. Here's a short snippet of the 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> 

Here's a snippet of the XAML where I reference the style:

<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> 

When I work in Expression Blend, everything looks fine. I see the change in the width of the drop down button for the control. Back in Visual Studio, everything compiles fine, but the change does not show up -- I see the default style for the control only, and the references to the style have a blue squiggly line under them. When you hover the mouse over the squiggly line, the following message is displayed:

 The resource "RadDateTimePickerControlTemplate1" cannot be resolved. 

The same thing happens if I change "DynamicResource" to "StaticResource" in the XAML. Also, I have made no changes to the Assembly.Info file for the project.

How do I fix this?

Thanks

Tony

2
  • Is the generic.xaml in the Themes folder of your project? Is the project really a WPF lib? and is this lib added as a reference in your project? Or is this generic.xaml in your application? You could try referencing your generic.xaml in your usercontrol resources via ResourceDictionary. Commented Sep 7, 2011 at 13:19
  • Yes, it's in the Themes folder of the project. It's really a WPF Library. Yes, it's added as a reference in my project. The library has a lot of UserControls and some CustomControls in it that are used elsewhere in the project. The same Generic.xaml file has the default control template for all of the CustomControls in the application and that's working fine. Can you give me an example of what you mean by "referencing your generic.xaml in your usercontrol resources view ResourceDictionary"? Commented Sep 7, 2011 at 13:24

1 Answer 1

3

As far as I remember you can't have named resources you want to reference in generic.xaml - that you have to put in app.xaml

You have to give the type in key for styles or ComponentResourceKey in key for controltemplates and in the class static constructor override metadata like:

 public class FlatStylebutton : Button { static FlatStylebutton() { DefaultStyleKeyProperty.OverrideMetadata(typeof(FlatStylebutton), new FrameworkPropertyMetadata(typeof(FlatStylebutton))); } } 

So a solution to your problem could be moving the style to app.xaml

Alternatively you can put it in a separate ResourceDictionary xaml file and import it in ResourceDictionary.MergedDictionaries

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Moving the style into App.xaml worked. I had to move it around in there to get it into a place that the compiler liked, but it's working now. I would like to know why it worked in Expression Blend if it wouldn't work after compiling, but not enough to go nuts over it. Thanks again!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.