I use a RadJumpList ItemTap event to pass a bound data item as a structure class to a RadWindow.Content with a DataTemplate set to display this content (username, password, domain, server fields). The user can then edit the fields accordingly and then press the save button on the appbar for the rad window. I catch this, grab the .content into as the data structure and write to a database. The issue is, only the origial data structure is captured and not the changed data.
I'll try to list an eample of what I'm doing. Please forgive any errors, but try to understand the idea of what is happening:
Sub ItemTap Event for RadJump List
Dim DataStructure as ServerInfo = Jumplist.SelectedItem
With RadWindow
'Set Properties
'Set DataTemplate
'Set Content
RadWindow.Content = DataStructure
End With
End Sub
Sub RadWindowAppBar_Click
If "Save" then
Dim DataStructure as ServerInfo = RadWindow.Content
'This is where the DataStructure is identical to before any edits of the TextBox's in DataTemplate
'Call Sub to save data pass DataStructure
End If
End Sub
5 Answers, 1 is accepted
Thank you for writing.
Please clarify whether this DataStructure is a Structure or a Class? If it is a Structure it will be boxed and will always be copied on assignment so you will always be modifying a temporary variable. This is the behavior of value types.
I am looking forward to you reply.
Victor
the Telerik team
Now that I'm back in the hotel I can remote in a grab some of my code to post.
Private
Sub
radJumpList_ItemTap(sender
As
Object
, e
As
Telerik.Windows.Controls.ListBoxItemTapEventArgs)
Handles
radJumpList.ItemTap
If
Not
radWindowServerInfo.IsOpen
Then
Dim
jumpList
As
RadJumpList = sender
Dim
serverInfoSend
As
New
ServerInfoSend
serverInfoSend = jumpList.SelectedItem
Dim
animation
As
New
RadScaleAndMoveAnimation
radWindowServerInfo.Content =
Nothing
With
radWindowServerInfo
.IsFullScreen =
True
.IsAnimationEnabled =
True
.OpenAnimation = animation
.CloseAnimation = animation.CreateOpposite
.PlacementTarget = radJumpList
.ContentTemplate = ContentTemplate
.Content = serverInfoSend
'.Content = jumpList.SelectedItem
.IsOpen =
True
End
With
End
If
End
Sub
Private
Sub
radWindowServerInfo_ApplicationBarButtonClick(sender
As
Object
, e
As
Telerik.Windows.Controls.ApplicationBarButtonClickEventArgs)
Handles
radWindowServerInfo.ApplicationBarButtonClick
Dim
radWindow
As
RadWindow = sender
Dim
serverInfoSend
As
New
ServerInfoSend
serverInfoSend = radWindow.Content
Dim
serverInfo
As
New
ServerInfo
For
Each
propInfo
As
PropertyInfo
In
serverInfo.
GetType
.GetProperties
propInfo.SetValue(serverInfo, propInfo.GetValue(serverInfoSend,
Nothing
),
Nothing
)
Next
If
e.Button.Text =
"Back"
Then
radWindowServerInfo.IsOpen =
False
ElseIf
e.Button.Text =
"Save"
Then
ProgressScreenToggle(1)
ServiceClient.SetServerConfigAsync(serverInfo)
radWindowServerInfo.IsOpen =
False
ElseIf
e.Button.Text =
"Delete"
Then
ProgressScreenToggle(1)
ServiceClient.DeleteServerConfigAsync(serverInfo)
radWindowServerInfo.IsOpen =
False
End
If
End
Sub
Thank you for the code.
I copy/pasted the code as it appears in this post and filled in the missing members and types, however, modifying the content property worked as expected. The modified value was always returned by the Content property of RadWindow. Please post a support ticket and submit a working application that demonstrates this behavior so that I may assist you further.
I am looking forward to your reply.
Victor
the Telerik team
"...The problem is in the binding of the text box. In Silverlight and WPF the textbox updates its binding only on lost focus. In WPF the developer can control this behavior but not in Silverlight. Currently you can force the binding by inserting an invisible UI element somewhere on the window and focusing it manually in the window closing event so that the text box loses focus..."
I was unaware that a TextBox only updated after it lost focus. So I looked at the TextBox class and found some interesting things that had me think about how I could force binding and I thought a more eligant approach would be more practical to what I could end up doing and also gave me some more options available like inline validation of text being typed in on a per character basis allowing for more functionality to be used if needed/wanted.
This also works on a PasswordBox also, not just a TextBox. Probably most other controls too. But since I am not an expert in such things, I am not sure. YMMV.
The idea was to take advantage of silverlights interaction behaviors. Here is some sample code that I came up with: (code slimmed down for easier reading)
First the XAML. If you set the UpdateSourceTrigger=Explicit this allows you to apply an Interaction Behavior that can fire. In the Behavior put in the name of the Class that will override the TextBox behavior.
<
TextBox
x:Name
=
"textBox"
Text
=
"{Binding Server, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
InputScope
=
"Url"
>
<
interactivity:Interaction.Behaviors
>
<
local:UpdateSourceOnTextChangedBehavior
/>
</
interactivity:Interaction.Behaviors
>
</
TextBox
>
Now for the magic code. This class overrides normal behaviors of the type you assign it to inherit (I use it on TextBox and PasswordBox so far). I has slimed down my code to just a basic version that works and allows the TextBox. But you should be able to get the idea of the power and capibilities it will give you (i.e. inline validation of text being typed on a per character basis allowing you to fire other code to do whatever you want, not just making sure the TextProperty is updated properly) OR (i.e being able to update a filter dynamically as the characters are typed to change things being displayed)
Behavior Class:
Public
Class
UpdateSourceOnTextChangedBehavior
Inherits
Behavior(Of TextBox)
Protected
Overrides
Sub
OnAttached()
MyBase
.OnAttached()
AddHandler
Me
.AssociatedObject.TextChanged,
AddressOf
OnTextChanged
End
Sub
Private
Sub
OnTextChanged(sender
As
Object
, e
As
TextChangedEventArgs)
Dim
be
As
BindingExpression =
Me
.AssociatedObject.GetBindingExpression(TextBox.TextProperty)
be.UpdateSource()
End
Sub
Protected
Overrides
Sub
OnDetaching()
MyBase
.OnDetaching()
RemoveHandler
Me
.AssociatedObject.TextChanged,
AddressOf
OnTextChanged
End
Sub
End
Class
So there it is. Maybe this is common knowledge I should have known, but I was so excited that I figured this out that I thought I would share my findings to help pay it forward. I am not an expert by any means, but I'm learning and will probably be asking for help more then I can provide it.
Thank you very much for the sharing your knowledge and for the enthusiasm. After all sharing ideas and knowledge is the driving force under every single community. We are happy to be of assistance. Also don't hold back on any questions you might have, the only way to become better is to ask questions and have them answered, one way or another :).
Best wishes,Victor
the Telerik team