Click here to Skip to main content
15,896,111 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
klauswiesel16-Mar-10 22:04
klauswiesel16-Mar-10 22:04 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
Super Lloyd17-Mar-10 1:40
Super Lloyd17-Mar-10 1:40 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
klauswiesel17-Mar-10 2:12
klauswiesel17-Mar-10 2:12 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
Super Lloyd17-Mar-10 2:55
Super Lloyd17-Mar-10 2:55 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
klauswiesel17-Mar-10 3:38
klauswiesel17-Mar-10 3:38 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
Super Lloyd17-Mar-10 12:21
Super Lloyd17-Mar-10 12:21 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
klauswiesel18-Mar-10 9:39
klauswiesel18-Mar-10 9:39 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
klauswiesel22-Mar-10 0:16
klauswiesel22-Mar-10 0:16 
Super Lloyd
allow me to come back to you in this issue.

Using the attached property solves the problem of getting the property of the current column, that works fine now.

The reason for using DataGridTemplateColumns have been that I want to have columns in my DataGrid that contain not only a textbox but additional controls (like a button in my case). These are working fine now, but what always was a pain in my app is the lengthy xaml code that is used for the template columns.

Now I started an alternative approach: I derived a new column type from DataGridTextColumn, and I am right now trying to overwrite the GenerateEditingElement event to show a usercontrol (with a textbox and a button in it). This works ok but changes to the textbox text property are not going "back" in my datagrid.

Maybe you have an idea?
I am using this in my datagrid:
<local:DerivedColumn Header="Usercontrol" Binding="{Binding FirstName, Mode=TwoWay}"></local:DerivedColumn>

This is my usercontrol xaml:
<Grid x:Name="grid1" MaxHeight="25">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="25"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<TextBox x:Name="txSelect" Text="{Binding UcText, Mode=TwoWay}" />
<Button x:Name="pbSelect" Background="Red" Grid.Column="1" Click="pbSelect_Click">...</Button>
</Grid>

... and the codebehind:
Public Class UcSelect

Private Shared Sub textChangedCallBack(ByVal [property] As DependencyObject, ByVal args As DependencyPropertyChangedEventArgs)
Dim UcSelectBox As UcSelect = DirectCast([property], UcSelect)
End Sub

Public Property UcText() As String
Get
Return GetValue(UcTextProperty)
End Get

Set(ByVal value As String)
SetValue(UcTextProperty, value)
End Set
End Property

Public Shared ReadOnly UcTextProperty As DependencyProperty = _
DependencyProperty.Register("UcText", _
GetType(String), GetType(UcSelect), _
New FrameworkPropertyMetadata(String.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, New PropertyChangedCallback(AddressOf textChangedCallBack)))

Public Sub New()

InitializeComponent()
grid1.DataContext = Me

End Sub

Private Sub pbSelect_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

'just demo
UcText = UcText + "!"

End Sub
End Class

And now the derived column:
Public Class DerivedColumn
Inherits DataGridTextColumn

Protected Overloads Overrides Function GenerateElement(ByVal oCell As DataGridCell, ByVal oDataItem As Object) As FrameworkElement

Dim oElement = MyBase.GenerateElement(oCell, oDataItem)
Return oElement

End Function

Protected Overloads Overrides Function GenerateEditingElement(ByVal oCell As DataGridCell, ByVal oDataItem As Object) As FrameworkElement

Dim oUc As New UcSelect
Dim oBinding As Binding = CType(Me.Binding, Binding)
oUc.SetBinding(UcSelect.UcTextProperty, oBinding)
Return oUc

End Function

End Class

This shows me the correct data, but changes are ignored (the are rolled back when leaving the grid cell)

Any help would be appreciated
Klaus
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
Super Lloyd22-Mar-10 14:16
Super Lloyd22-Mar-10 14:16 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
klauswiesel22-Mar-10 23:13
klauswiesel22-Mar-10 23:13 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
Super Lloyd23-Mar-10 11:43
Super Lloyd23-Mar-10 11:43 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
klauswiesel23-Mar-10 11:51
klauswiesel23-Mar-10 11:51 
GeneralRe: Get binding of control in datagridtemplatecolumn Pin
Super Lloyd23-Mar-10 20:47
Super Lloyd23-Mar-10 20:47 
QuestionHelp with textbox for calculator Pin
Sonar8715-Mar-10 14:47
Sonar8715-Mar-10 14:47 
AnswerRe: Help with textbox for calculator Pin
Not Active15-Mar-10 15:45
mentorNot Active15-Mar-10 15:45 
GeneralRe: Help with textbox for calculator Pin
Sonar8716-Mar-10 13:54
Sonar8716-Mar-10 13:54 
GeneralRe: Help with textbox for calculator Pin
Not Active16-Mar-10 14:20
mentorNot Active16-Mar-10 14:20 
GeneralRe: Help with textbox for calculator Pin
Sonar8716-Mar-10 18:26
Sonar8716-Mar-10 18:26 
GeneralRe: Help with textbox for calculator Pin
guyet053-Aug-10 17:25
guyet053-Aug-10 17:25 
Questionhow to use silverlight tool in .aspx page Pin
DX Roster14-Mar-10 20:22
DX Roster14-Mar-10 20:22 
AnswerRe: how to use silverlight tool in .aspx page Pin
Abhinav S14-Mar-10 20:44
Abhinav S14-Mar-10 20:44 
QuestionC# code Equivalent in wpf Pin
amir-haghighi13-Mar-10 7:15
amir-haghighi13-Mar-10 7:15 
AnswerRe: C# code Equivalent in wpf Pin
Super Lloyd15-Mar-10 11:15
Super Lloyd15-Mar-10 11:15 
QuestionTab ordering in WPF controls. Pin
SRKSHOME11-Mar-10 23:15
SRKSHOME11-Mar-10 23:15 
QuestionWPF TextBox shrinks but Stackpanel doesn't Pin
Marcelo Ricardo de Oliveira11-Mar-10 8:58
Marcelo Ricardo de Oliveira11-Mar-10 8:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.