Monday, October 29, 2012

How to get checkbox checked event in silverlight, from Data Template .

How to get checkbox checked event in silverlight, from Data Template .

Hi all, i am creting a data template at runtime and binding it to a RadCombobox in silverlight.

 Dim radCmb As RadComboBox

radCmb = New RadComboBox
radCmb.Name = "cmb" + index.ToString()

radCmb.Width = 150

Dim template1 As DataTemplate = DirectCast(XamlReader.Load("<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007"">" & vbCr & vbLf & "<StackPanel Orientation=""Horizontal"">" & vbCr & vbLf & "                        <CheckBox Name=""chkSelect"" Content=""{Binding DeviceID}"" Tag=""{Binding InternalDeviceID}""/>" & vbCr & vbLf & "                        <TextBlock Text=""{Binding Name}""/>" & vbCr & vbLf & "                    </StackPanel>" & vbCr & vbLf & "                  </DataTemplate>"), DataTemplate)

radCmb.ItemTemplate = template1

now i need to capture the check box checked and unchecked event and the corresponding checked or unchecked value.

Can you suggest me to achieve this functionality.

thanks

skm

Answers & Comments...

Answer: 1

See if this helps:

http://stackoverflow.com/questions/9413791/how-to-select-all-checkbox-inside-telerik-combox-on-checbox-checked-event



Answer: 2

Can't you just add an IsChecked boolean property to your Viewmodel?  Then just bind to it like you are doing your Text Name property?



Answer: 3

Binding to the IsChecked Property will tell only the state of the checkbox. It will not help to get the Text of the checkbox.

mtiede: Do you think it required a Command and Command Parameter? I am trying to understand, kindly provide your valuable comment.



Answer: 4

You said:

"now i need to capture the check box checked and unchecked event and the corresponding checked or unchecked value."

If whatever structure you have that contains the Name property that is bound to your TextBox also has an IsChecked Boolean property, then you can just bind the CheckBox IsChecked attribute to the IsChecked property of your Viewmodel.

I'm not sure what you mean by: "It will not help to get the Text of the checkbox."  You haven't said there was any relationship between the Text and the IsChecked.

I don't know if a Command is needed, it depends on what you are ultimately trying to do.  I don't think you have stated clearly what you are trying to accomplish.

If you have a Viewmodel that contains both the Name and the IsChecked property and something else that creates the Viewmodel, that other thing can listent for changes to the Viewmodel properties and take actions if they want.  If the Viewmodel itself is to take some action when the property changes, then the Viewmodel can just add the appropriate code when the property setter is called.





No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog