<sf:SfDataGrid.Columns>
<sf:GridTemplateColumn MappingName="Name" >
<sf:GridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox sf:FocusManagerHelper.FocusedElement="True"
FontStyle="Italic"
FontWeight="SemiBold"
Padding="2,0"
Text="{Binding Name}" />
</DataTemplate>
</sf:GridTemplateColumn.CellTemplate>
</sf:GridTemplateColumn>
</sf:SfDataGrid.Columns> |
public class TestTextRenderer : GridVirtualizingCellRenderer<TextBlock, TestTextBox>
{
protected override void OnEditElementLoaded(object sender, System.Windows.RoutedEventArgs e)
{
var uiElement = (TestTextBox)sender;
//Set the focus to the edit element.
uiElement.Focus();
}
public override void OnInitializeEditElement(DataColumnBase dataColumn, TestTextBox uiElement, object dataContext)
{
base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
uiElement.SetBinding(TextBox.TextProperty, dataColumn.GridColumn.ValueBinding);
// Here we set other things like background (input required, read only and more) and clear button visibility
}
} |
public class TestCheckBoxRenderer : GridCellCheckBoxRenderer
{
protected override CheckBox OnCreateEditUIElement()
{
return new TestCheckBox();
}
}
public class TestCheckBox : CheckBox
{
} |
DataGrid.CellRenderers.Remove("CheckBox");
DataGrid.CellRenderers.Add("CheckBox", new TestCheckBoxRenderer());
public class TestCheckBoxRenderer : GridVirtualizingCellRenderer<TestCheckBox, TestCheckBox>
{
public TestCheckBoxRenderer()
{
SupportsRenderOptimization = false;
IsEditable = false;
}
public override void OnInitializeEditElement(DataColumnBase dataColumn, TestCheckBox uiElement, object dataContext)
{
base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
var column = dataColumn.GridColumn;
uiElement.FocusVisualStyle = null;
uiElement.SetValue(FrameworkElement.VerticalAlignmentProperty, column.VerticalAlignment);
var checkBoxColumn = column as GridCheckBoxColumn;
if (checkBoxColumn == null)
return;
uiElement.SetValue(FrameworkElement.HorizontalAlignmentProperty, checkBoxColumn.HorizontalAlignment);
}
public override void OnUpdateEditBinding(DataColumnBase dataColumn, TestCheckBox element, object dataContext)
{
OnInitializeEditElement(dataColumn, element, dataContext);
}
} |