Home Forums WPF controls Xceed DataGrid for WPF Host a WinForm control

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • Xceed Support
    Member
    Post count: 5658
    #24440 |

    Hi,

    I know in WPF there is a way to host a WinForm control into a user control.

    I was wandering if it were possible the used that user control and use it has a cell editor?

    If it’s possible, is it complicated?
    How to do it?

    Thanks in advance.

    Imported from legacy forums. Posted by Simon (had 606 views)

    User (Old forums)
    Member
    Post count: 23064

    //this is psuedo code to give you the idea, I dont know if the idea will actually work

    xmlns:wfi=”clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration”
    xmlns:wf=”clr-namespace:System.Windows.Forms…”//set to the control dll you want to use


    <Resources>
    <DataTemplate x:Key=”WFIDataTemplate”>
    <wfi:WindowsFormsHost Width=”250″ Height=”150″>
    <wf:YourWinFormControl x:Name=”MyControl” />
    </wfi:WindowsFormsHost>
    </DataTemplate>
    </Resources>

    //In Code Behind-I feel is the best way to set this

    public DataTemplate getCellTemplate(string templateKey)
    {
    DataTemplate dt = this[templateKey] as DataTemplate;
    if (dt == null)
    return this[“StringDataTemplate”] as DataTemplate;
    return dt;
    }

    //where your grid is in code
    Column c new Column();
    c.CellContentTemplate = getCellTemplate(“WFIDataTemplate”);

    …….

    this is just ideas i got from my app. in theory it should work. My app has:
    a resource dictionary with all the DataTemplates in it.
    code behind on the resouce dictionary with functions like getCellTemplate() to get the Xaml into c#
    then I set up my grids in codebehind calling the methods on the resourcedictionary object I inherited from;

    sorry if this is confusing I didnt have a lot of time to explain myself
    but also hope the ideas will steer you in the correct direction.
    the xmlns:wf line needs to be modified for the namespace and assembly(dll) the control you want to use is in;

    Imported from legacy forums. Posted by MiddleTommy (had 294 views)

    User (Old forums)
    Member
    Post count: 23064

    Sorry but for an editro
    <xcdg:CellEditor x:Key=”WFCellEditor”>
    <xcdg:CellEditor.EditTemplate>
    <DataTemplate>
    here put the datatemplate from above
    </DataTemplate>
    </xcdg:CellEditor.EditTemplate>
    <xcdg:CellEditor.ActivationGestures>
    <xcdg:TextInputActivationGesture />
    </xcdg:CellEditor.ActivationGestures>
    </xcdg:CellEditor>

    also in the datatemplate add a binding to one of the peoperties to the ActualContent property of the cell

    Imported from legacy forums. Posted by MiddleTommy (had 216 views)

    User (Old forums)
    Member
    Post count: 23064

    binding example in xamle

    <wf:TextBox Text=”{Binding RelativeSource={RelativeSource FindAncestor,
    AncestorType=xcdg:Cell},
    Path=ActualContent,
    UpdateSourceTrigger=PropertyChanged,
    Converter={StaticResource IntConverter}}”
    />

    Imported from legacy forums. Posted by MiddleTommy (had 4015 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.