Style & Template Issues

3 posts, 0 answers
  1. Wayne Williams
    Wayne Williams avatar
    38 posts
    Member since:
    Jul 2019

    Posted 11 Aug Link to this post

    Hi,

    I'm running into some problems applying new style & template settings to AutoCompleteBox.

    I've read this article: https://docs.telerik.com/devtools/wpf/styling-and-appearance/styling-apperance-editing-control-templates,and I've created a simple default Telerik application that has only an AutoCompleteBox defined:

    <Window x:Class="TelerikWpfApp1.MainWindow"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    Title="MainWindow" Height="350" Width="525">
            <Grid>
                <telerik:RadAutoCompleteBox />   
            </Grid>
    </Window>

    If I use VS to generate a copy of the required template (i.e. right-click the RadAutoCompleteBox, Edit Template ->Edit a Copy..., etc., I get this error message:

    InvalidCastException: [A]Telerik.Windows.Controls.RadListBox cannot be cast to [B]Telerik.Windows.Controls.RadListBox. Type A originates from 'Telerik.Windows.Controls, Version=2019.2.618.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7' in the context 'LoadNeither' at location 'C:\Users\WWill\AppData\Local\Microsoft\VisualStudio\16.0_789bb273\Designer\ShadowCache\gmfvgqnw.h3w\4sct5rze.jm2\Telerik.Windows.Controls.dll'. Type B originates from 'Telerik.Windows.Controls, Version=2019.2.618.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7' in the context 'LoadFrom' at location 'C:\Program Files (x86)\Progress\Telerik UI for WPF R2 2019\Binaries\WPFRadF45\Telerik.Windows.Controls.dll'.

    If, instead, I open the Telerik.Windows.Controls.Input.xaml file and copy the relevant RadAutoCompleteBox styles/templates into a resource dictionary in my application, I find a great many dependencies on other definitions in that file, which triggers a lot of "not found" reference errors.

    So, I copied the entire ResourceDictionary from that file into my test app. Not too happy about copying 7,500 lines of code anywhere, but, hey, I'll try anything once. Unfortunately, I'm still getting errors, this time 28 of them in the form:

    Severity Code Description Project File Line Suppression State
    Error XDG0044 The local property "Columns" can only be applied to types that are derived from "RadUniformGrid". TelerikWpfApp1 App.xaml 5334 

    As these did not stop me from building/running my app, I proceeded to modify my RadAutoCompleteBox definition as follows:

    <telerik:RadAutoCompleteBox TextBoxStyle="{DynamicResource RadAutoCompleteTextBoxStyle}"/> 

    This resulted in the following message:

    InvalidOperationException: 'RadWatermarkTextBox' TargetType does not match type of element 'RadWatermarkTextBox'.

    Again, this error doesn't stop me from compiling/running the app, but I thought I'd mention it in case it's an indicator

    Finally, despite all the aforementioned errors, I am able to tweak the appearance of my RadAutoCompleteBox control, but I'm not feeling too good about it, as it seems like a very inelegant way to achieve a few visual tweaks.

    Any advice for a newbie?

    Wayne

     

     

  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2240 posts

    Posted 14 Aug Link to this post

    Hello Wayne,

    The automatic extraction of the style/template (using Visual Studio or Blend) doesn't always extracts the style properly. This is why I would recommend you to get the style from the Telerik.Windows.Controls.Input.xaml as you already tried. Note that the .xaml file contains all the resources required by the style, but you will need to find and copy them in your project along with the style.

    Here are few steps that you can try in order to achieve your requirement:

    1. Open the Telerik.Windows.Controls.Input.xaml file.
    2. Find the Style with x:Key="RadAutoCompleteBoxStyle" and copy it into your project.
    3. Find all the related resources from the Style, referenced with the StaticResource keyword and copy them into your project. For example, the RadAutoCompleteBoxTemplate. Also, in the template you will find some StaticResource references that point to brushes, styles and other resources. Copy all of those and add them into your project.

    If this doesn't help, can you please tell me which theme do yo use?

    Regards, Martin Ivanov
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Wayne Williams
    Wayne Williams avatar
    38 posts
    Member since:
    Jul 2019

    Posted 14 Aug in reply to Martin Ivanov Link to this post

    No, it helps. This is one of those situations where it doesn't feel good to be doing so much copying and pasting, so you want confirmation that you're doing it correctly. So, knowing that, I'll work my way through it, thanks.

    Wayne

Back to Top