LabelProperties do not listen on property change when DataContext is set after InitializeComponent

3 posts, 0 answers
  1. Robert
    Robert avatar
    8 posts
    Member since:
    Apr 2009

    Posted 02 Jul 2009 Link to this post

    If i have a trigger on IsEnabled in my LabelProperties style an bind that to a DependecyProperty in my ViewModel the Trigger will not 'fire' when i set the DataContext after InitilizeComponent only if i set it before. The problem with this is that IsEnable will  not work if i set the DataContext in xaml on a UserControl containing the gauge. I think that this is a faulty behavior because Minor/MajorTickStyle works if i set the DataContext after InitilizeComponent.

    well this thread is useless without code so...

    my usercontrol

    <UserControl x:Class="WpfTest_Telerik.UserControl1" 
        Width="300" Height="300">  
            <Style x:Key="MajorTickStyle" TargetType="{x:Type telerik:TickProperties}">  
                <Setter Property="Background" Value="White" /> 
                    <Trigger Property="IsEnabled" Value="False">  
                        <Setter Property="Background" Value="Black" /> 
            <Style x:Key="LabelProperties" TargetType="{x:Type telerik:LabelProperties}">  
                <Setter Property="Foreground" Value="White" /> 
                    <Trigger Property="IsEnabled" Value="False">  
                        <Setter Property="Foreground" Value="Black" /> 
                            <telerik:TickProperties IsEnabled="{Binding Path=IsActive}" Style="{StaticResource MajorTickStyle}"/>  
                        <telerik:RadialScale.Label > 
                            <telerik:LabelProperties IsEnabled="{Binding Path=IsActive}"  Style="{StaticResource LabelProperties}" /> 

    code behind

    using System.Windows.Controls;  
    namespace WpfTest_Telerik  
        /// <summary>  
        /// Interaction logic for UserControl1.xaml  
        /// </summary>  
        public partial class UserControl1 : UserControl  
            public UserControl1()  
                // will work  
                //DataContext = new UserControl1ViewModel();  
                // will not work  
                DataContext = new UserControl1ViewModel();  

    my viewmodel

    using System;  
    using System.Windows;  
    using System.Timers;  
    using System.Windows.Threading;  
    namespace WpfTest_Telerik  
        public class UserControl1ViewModel : DependencyObject  
            private readonly Dispatcher _currentDispatcher;  
            public UserControl1ViewModel()  
                _currentDispatcher = Dispatcher.CurrentDispatcher;  
                var timer = new Timer(2000);  
                timer.Elapsed += TimerElapsed;  
            void TimerElapsed(object sender, ElapsedEventArgs e)  
                Action x = () => IsActive = !IsActive;  
            public bool IsActive  
                get { return (bool)GetValue(IsActiveProperty); }  
                set { SetValue(IsActiveProperty, value); }  
            // Using a DependencyProperty as the backing store for IsActive.  This enables animation, styling, binding, etc...  
            public static readonly DependencyProperty IsActiveProperty =  
                    DependencyProperty.Register("IsActive"typeof(bool), typeof(UserControl1ViewModel), new UIPropertyMetadata(false));  
  2. Andrey
    Andrey avatar
    1681 posts

    Posted 03 Jul 2009 Link to this post

    Hi Robert,

    It seems there is a problem in using of data context inheritance with other inheritable properties like to the Foreground or font related properties.
    I think as workaround you could use a binding to setup the data context for gauge labels.
    As sample you could add the following setter to your LabelProperties style:
    <Setter Property="DataContext" Value="{Binding}" />

    Kind regards,
    Andrey Murzov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft R3 2016 release webinar banner
  4. Robert
    Robert avatar
    8 posts
    Member since:
    Apr 2009

    Posted 06 Jul 2009 Link to this post

    Works like a charm now, thanks!
Back to Top