Scenario:
While using DevExpress WPF control, sometimes it requires to convert the binding value according to the control’s property. In that case we need use the Value Converters in this case.
Let we require to bind the SpinEdit WPF control edit value property with some object property which require to be converted to decimal value. To do that we need to follow below steps:
- Create a custom converter class which implements IValueConverter to convert the value to the decimal.
namespace DevExWpfApp
{
public class DecimalConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return System.Convert.ToDecimal(value);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
- Now use it in the XAML by declare it as resources and then call it as below:
<UserControl.Resources>
<local:DecimalConverter x:Key="DecimalConverter"/>
</UserControl.Resources>
<dxe:SpinEdit EditValue="{Binding Entity.MaxValue, Converter={StaticResource DecimalConverter}" />
Scenario:
Current requirement is that user can select option from drop down from mouse selection only, but whenever use type anything in the drop down it automatically raise control’s ComboBox.SelectionChangeCommitted event with first match that satisfies auto complete condition of the control. As required we need ignore the key press to raise the ComboBox.SelectionChangeCommitted event of the combo box and it only allow selection only on mouse.
Solution:
To do this, I set the control’s DropdownStyle set to DropDownList, but no work correctly. Along this I have to suppress combo box’s key press by handling KeyDown event as below.
LibraryListDropdown libDropdown = null;
public Form1()
{
InitializeComponent();
libDropdown = new LibraryListDropdown();
this.libDropdown.DropDownStyle = DropDownStyle.DropDownList;
libDropdown.Name = "cmbObjectType";
libDropdown.SelectionChangeCommitted += new EventHandler(libDropdown_SelectionChangeCommitted);
libDropdown.KeyDown += libDropdown_KeyDown;
this.Controls.Add(libDropdown);
libDropdown.PopulateLibraries();
}
void libDropdown_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = true;
}
private void libDropdown_SelectionChangeCommitted(object sender, EventArgs e)
{
}
Create a Class that inherits ITemplate and add controls the container ; you want to add.
Assign the object of that class to ASPxGridView's Templates.FooterRow property as:
ASPxGridView1.Templates.FooterRow = new CustomFooterRowTemplate();
And the code snippet of the template class is below:
public class CustomFooterRowTemplate: ITemplate
{
void ITemplate.InstantiateIn(Control container)
{
Button button = new Button();
button.Text = "Test";
container.Controls.Add(button);
}
}
have an idea from this and you can add more controls and even you can use their event handler in the custom template except using on the RowCommand event.