This is a migrated thread and some comments may be shown as answers.

Implementation Ideas? or lack there of... (Round 2!)

3 Answers 54 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 08 Mar 2016, 07:37 PM

Hello All,

I would first like to thank Martin again, he's sample got me pretty far.  In fact in the first sample included below, I got my Labels and the slider bar behaving as I would like.  When I tried porting over to my main application (the second sample below Sample2), I got some BUT not all behavior...  Namely, the trackbar is not coloring correctly, nor does it have the proper thumbs, for the selector.  I see in Martin's sample code that there is an application resource defined in the app.xaml file.  

 

<Application x:Class="BaseApplicationProject.App"
      
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             
StartupUri="MainWindow.xaml">
    <
Application.Resources>
        <
ControlTemplate x:Key="largeDecreaseButtonTemplate" TargetType="{x:Type RepeatButton}">
            <
Grid Background="{TemplateBinding Background}"/>
        </
ControlTemplate>
    </
Application.Resources>
</
Application>

 

 

However, my lack of familiarity with this has caused some problems.  You see in my main app the App.xaml file has a ResourceDictionary defined:

 

<Application x:Class="Worms.App"
     
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     
              Startup="OnStartup" Exit="OnExit">
    <
Application.Resources>
        <
ResourceDictionary>
            <
ResourceDictionary.MergedDictionaries>
               
 <ResourceDictionary Source="/Fluent;Component/Themes/Generic.xaml" />                 <ResourceDictionary Source="/Fluent;Component/Themes/Office2010/Silver.xaml" />                 <ResourceDictionary Source="Theme/Colors/Silver.xaml"/>                 <ResourceDictionary Source="Theme/Theme.xaml"/>                 <ResourceDictionary Source="Theme/Resources.xaml"/>                 <ResourceDictionary Source="pack://application:,,,/AvalonDock.Themes;component/themes/dev2010.xaml"/>                 <ResourceDictionary Source="Theme/AvalonDockTheme.xaml"/>
            </
ResourceDictionary.MergedDictionaries>
        </
ResourceDictionary>
    </
Application.Resources>
</
Application>

 

So, I tried to put the ControlTemplate in one of the included files of the ResourceDictionary, more precisely into either Theme/Theme.xaml or Theme/Resources.xaml.  Neither one seemed to work.  The problem I get is a Null reference in the SliderUtilities.cs file in the slider_Loaded function:

 

1.static void slider_Loaded(object sender, RoutedEventArgs e)
2.{
3.    var slider = (RadSlider)sender;
4.    var button = slider.ChildrenOfType<RepeatButton>().FirstOrDefault(x => x.Name == "LargeDecreaseButton");
5.    button.Template = (ControlTemplate)Application.Current.Resources["largeDecreaseButtonTemplate"];
6.     
7.    slider.Tag = button;
8.}

 

When I step through this function in Martin's sample after line 4 is executed, button is instantiated to a good value.  In my main app, when I step through the same function, button is null...  Not Good!  Also the slider variable in Martin's sample has an instantiated decreaseButton and increaseButton of type System.Windows.Controls.Primitives.RepeatButton.  In my main app, they are both null....

Any ideas why the slider control/variable is NOT picking up the ControlTemplate for the repeatbuttons???

 

Thanks again in advance!,

 

Kevin Orcutt
Senior Software Engineer

Wurth Electronics ICS, Inc.
7496 Webster St., Dayton, OH 45414
Tel: 937.415.7700 
Toll Free: 877.690.2207
Fax: 937.415.7710
Email: kevin.orcutt@we-ics.com
http://www.we-ics.com

3 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 1
answered on 09 Mar 2016, 05:07 PM

Well All,
     After fussing around for a bit...,  I finally got the trackbar color to work.  However, the button is still messed up.  One possible key item, is that the slider is on a tabcontrol/tabitem, and it is not the initial tab displayed.  I've tried temporary making that particular tab to be the selected index on the tabcontrol making it the initial tab displayed, that didn't help. After further observation, I have found out that as stated in my first message, the button is null on the first display of this tab.  If you change tabs and then come back to this one, then the button is finally initialized to a RepeaterButton on slider_Loaded function...  Not sure if that helps out any, but I thought I might get it out there to offer any help.
      It seems to be an Instantiation/Initialization issue maybe?!?!

 

Thanks again,

 

Kevin Orcutt

0
Kevin
Top achievements
Rank 1
answered on 10 Mar 2016, 05:15 PM

Here's a sample of what the slider button looks like...  Not to useful  I would much rather have the larger button that Martin was able to produce...

Go figure...

 

 

0
Kiril Vandov
Telerik team
answered on 11 Mar 2016, 03:28 PM
Hello Kevin,

I am not sure how exactly you copied the changes that Martin provided in the previous conversation but they should be applied pretty straight forward and work without problem. Based on the provided picture I could say that the button size is set to a too small value and it not stretched to the entire space it could take. Could you please provide us with a sample project with your implementation to further investigate the cause.

Looking forward to hearing from you.

Kind regards,
Kiril Vandov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Slider
Asked by
Kevin
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 1
Kiril Vandov
Telerik team
Share this question
or