Hello,
i'm trying to create some Editors as Custom Controls which i would use in a datagrid created in codebehind.
All works fine but i wanted to create a Custom Control which derives from the CellValuePresenter class.
The Template of my class is a Button.
The Control looks good but if i want to bind my Custom Control to the Settings.CellValuePresenterStyle of my field, an exception is thrown, which says my Custom Control is not a CellValuePresenter Class.
what can i do?
Here's the code of the Custom Control:
[TemplatePart(Name = "PART_DhpButton", Type = typeof(Button))] public class DhpButtonEditor : CellValuePresenter { static DhpButtonEditor() { DefaultStyleKeyProperty.OverrideMetadata(typeof(DhpButtonEditor), new FrameworkPropertyMetadata(typeof(DhpButtonEditor))); } #region Events public override void OnApplyTemplate() { base.OnApplyTemplate(); Button dhpButton = base.GetTemplateChild("PART_DhpButton") as Button; if (dhpButton != null) { dhpButton.Click += new RoutedEventHandler(DhpButton_Click); } } public delegate void Click_EventHandler(Object sender, RoutedEventArgs e); public event Click_EventHandler Click; private void DhpButton_Click(object sender, RoutedEventArgs e) { if (this.Click != null) this.Click(sender, e); } #endregion }here's the xaml code:
<Style x:Key="{x:Type local:DhpButtonEditor}" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <Button Name="PART_DhpButton" Margin="0,0,0,0" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Content="{TemplateBinding Content}" /> </ControlTemplate> </Setter.Value> </Setter> </Style>
i try to bind the custom control like this:
Field field = new Field("Button"); field.Width = new FieldLength(50, FieldLengthUnitType.Auto); Style buttonStyle = new Style(typeof(DhpButtonEditor)); field.Settings.CellValuePresenterStyle = buttonStyle; fieldLayout.Fields.Add(field);
i attached an examle!
THanks for the help.
Jochen
I have been looking into your issue and I believe that you would like to define you own value editor, not new CellValueEditor. I have modified your sample application(DhpControlsModified.zip) in order to achieve the desired functionality. I would like to suggest you define styles for CellValuePresenter in XAML as it is shown in the following forum thread :
http://help.infragistics.com/Help/NetAdvantage/WPF/2011.1/CLR4.0/html/InfragisticsWPF4.DataPresenter.v11.1~Infragistics.Windows.DataPresenter.FieldSettings~CellValuePresenterStyle.html
If you have any other questions on this matter, feel free to ask.
Thank you very much for the example and the link!
This solved my problem!
Sincerely,Jochen