WPF DataGrid binding to UserControl

Posted by Trindaz on Stack Overflow See other posts from Stack Overflow or by Trindaz
Published on 2010-04-23T09:13:21Z Indexed on 2010/04/29 0:47 UTC
Read the original article Hit count: 1611

I have a DataGrid with one column using a UserControl via a styled DataGridTemplateColumn. I can't seem to get the UserControl to 'see' the object that is in it's containing DataGridCell though. What kind of bindings can I create on the TextBox in my UserControl so that it can look up and see that object?!

My UserControl and TemplateColumn Style are defined as:

    <local:UCTest x:Key="UCTest" />
    <Style x:Key="TestStyle" TargetType="{x:Type WpfToolkit:DataGridCell}">
            <Setter Property="Template">
                    <ControlTemplate TargetType="{x:Type WpfToolkit:DataGridCell}">
                        <Grid Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource drc}, Path=DataContext}">
                            <local:UCTest />    

and my sample DataGrid is defined as:

                CellStyle="{StaticResource TestStyle}"

and my User Control is defined in a separate file as:

<UserControl x:Class="UCTest"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="104" Height="51">
    <local:DataRowConverter x:Key="drc" />
    <TextBox Margin="12,12,-155,16" Name="TextBox1" Text="" />


My implementation of TestClass, which has the Test Property, which I want UCTest.TextBox1 to bind do:

Public Class TestClass

Private _Test As String = "Hello World Property!"
Public Property Test() As String
        Return _Test
    End Get
    Set(ByVal value As String)
        _Test = value
    End Set
End Property

End Class

Thanks in advance!

© Stack Overflow or respective owner

Related posts about wpf

Related posts about wpfdatagrid