Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Toggling between two styles on click of a button for activecell
posted

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.

private void ToggleButton_Click(object sender, RoutedEventArgs e)

{

object customComboStyle;

customComboStyle = this.LayoutRoot.Resources["customMixedNumericEditor"];

this.xamDCPViewer.ActiveCell.EditorStyle = (Style)customComboStyle;

 

 

 

 

}

private void ToggleButton2_Click(object sender, RoutedEventArgs e)

{

object customComboStyle;

customComboStyle = this.LayoutRoot.Resources["customMixedComboEditor"];

 this.xamDCPViewer.ActiveCell.EditorStyle = (Style)customComboStyle;

}

 

<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 Grid.Column="0" Click="ToggleButton_Click">Toggle

</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">

<Setter Property="EditTemplate">

<Setter.Value>

<ControlTemplate TargetType="igEditors:XamTextEditor">

<Grid>

<Grid.ColumnDefinitions>

<ColumnDefinition Width="Auto"></ColumnDefinition>

<ColumnDefinition></ColumnDefinition>

</Grid.ColumnDefinitions>

<Button Grid.Column="0" Click="ToggleButton2_Click">Toggle</Button>

<ccl:NumericUpDown Grid.Column="1" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, Mode=TwoWay}"/>

</Grid>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

Parents
No Data
Reply
  • 180
    posted

    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.

Children
No Data