1

I am developing a system with voice commands that apply to a grid of parameters. I want to apply a style to the element being edited, so that the user knows where he is vocally ...

MyView.xaml

 <telerik:RadNumericUpDown Name={Binding Element[0].ID}  Grid.Column="0" Name="Left" MinWidth="15" FontSize="11" Minimum="0" NumberDecimalDigits="0" 
BorderThickness="0" Maximum="30" 
IsInteger="True" ShowButtons="False" ShowTextBox="True" 
HorizontalContentAlignment="Left"  Value="{Binding Element[0].Input, Mode=TwoWay, ElementName=InputViewUserControl}" Background="Transparent" Foreground="#FF858585"  />


 <telerik:RadNumericUpDown Name={Binding Element[1].ID}  Grid.Column="0" Name="Left" MinWidth="15" FontSize="11" Minimum="0" NumberDecimalDigits="0" 
BorderThickness="0" Maximum="30" 
IsInteger="True" ShowButtons="False" ShowTextBox="True" 
HorizontalContentAlignment="Left"  Value="{Binding Element[1].Input, Mode=TwoWay, ElementName=InputViewUserControl}" Background="Transparent" Foreground="#FF858585"  />

 <telerik:RadNumericUpDown Name={Binding Element[2].ID}  Grid.Column="0" Name="Left" MinWidth="15" FontSize="11" Minimum="0" NumberDecimalDigits="0" 
BorderThickness="0" Maximum="30" 
IsInteger="True" ShowButtons="False" ShowTextBox="True" 
HorizontalContentAlignment="Left"  Value="{Binding Element[2].Input, Mode=TwoWay, ElementName=InputViewUserControl}" Background="Transparent" Foreground="#FF858585"  />

.....i have 30 elements So...

If the user says: element one, I'd like to apply style to Element[0]

If you have an idea let me know Thanks :)

Allel
  • 109
  • 9
  • Consider changing style in LostFocus, GotFocus and setting focus based on your voice processing function. – IntStarFoo Dec 05 '13 at 15:13
  • 1
    `....i have 30 elements So...` - Please remove all that horrible repetition immediately and use an `ItemsControl`. – Federico Berasategui Dec 05 '13 at 15:27
  • @Allel The question is how to know what is the voice, or after you know what the voice was, how to change the style? – Programmer Dec 05 '13 at 15:36
  • :) this is solution of my problem http://stackoverflow.com/questions/1356045/set-focus-on-textbox-in-wpf-from-view-model-c-wpf – Allel Dec 05 '13 at 16:46

1 Answers1

2

You just need one Style in a Resources section and then you need to add one bool IsSelected property to your Element class:

public bool IsSelected { get; set; } // Implement INotifyPropertyChanged interface here

<Style TargetType="{x:Type telerik:RadNumericUpDown}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding IsSelected}" Value="True">
            <Setter Property="Background" Value="LightGreen" />
        </DataTrigger>
    </Style.Triggers>
</Style>

The Style will colour the Background of the object that has an IsSelected property that is set to True. All you need to do now is to set the IsSelected property to True for the current object and set the previous object's IsSelected value to False.

Note that this Style has no x:Key value... that means that it will be implicitly set on all of your controls without you needing to set the Style on each element manually.

Sheridan
  • 68,826
  • 24
  • 143
  • 183