I have a xamdatagrid. I have created two styles for the cell to chose the editor style from. One of the style has button and numericeditor with up/down control and the other style is with button and combobox. The button in both of these styles is toggle button and I want to switc between these two editor style for the active cell. If the user click toggle button he should be able to switch between combobox and numeric up down control. On the onclick event of the button i am changing the editor style to the other one. But it's not working. Am I missing something. I am pasting the codE: How to switch between different editor styles on click of a button from withing the current active style.
{
customComboStyle = this.LayoutRoot.Resources["customMixedNumericEditor"];
this.xamDCPViewer.ActiveCell.EditorStyle = (Style)customComboStyle;
}
customComboStyle = this.LayoutRoot.Resources["customMixedComboEditor"];
<Style TargetType="{x:Type igEditors:XamTextEditor}" x:Key="customMixedComboEditor">
<Setter Property="EditTemplate">
<Setter.Value>
<ControlTemplate TargetType="igEditors:XamTextEditor">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
</Button>
<ComboBox Name="EnumValues" Grid.Column="1" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, Mode=TwoWay}" SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, Mode=TwoWay}" ItemsSource="{Binding Path= DataItem.EnumValues}" ></ComboBox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type igEditors:XamTextEditor}" x:Key="customMixedNumericEditor">
<Button Grid.Column="0" Click="ToggleButton2_Click">Toggle</Button>
<ccl:NumericUpDown Grid.Column="1" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, Mode=TwoWay}"/>
I am pretty sure you can do this using Triggers in XAML instead of handling the click event in the code. Write a Style with a trigger that sets the Template property to the correct ControlTemplate based on the value of IsChecked on the ToggleButton. If I have time later, I will write out an example, but I wanted to point you in this direction as I have used this concept in the XAMDataGrid.