This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi- I'm trying to develop a property editor consisting of a group of radio buttons. It's easy to set the property value based on which radio button I click. The problem I'm having is going in the other direction. When the property grid comes up, how do I intialize which button is checked based on what the property value is? The property value type can be an enum or a string, I don't care which. With a list, you just bind the SelectedItem to the property value. But with a group of radio buttons, I'm not sure what to do. Is there a way to programatically access the IsChecked property of the individual buttons within the editor? Thanks. |
|
|
Let me flip the question and suggest an alternative approach. Instead of thinking of the editor as a group of radio buttons, think of it as a ListBox, with the ItemTemplate being a radio button. Then you bind ListBox.SelectedItem to the property value, and RadioButton.IsChecked to ListBoxItem.IsSelected. (This is in fact how the "drop-down radio button group" built-in editor works -- it's a plain old ComboBox with an ItemTemplate.) Not sure whether this will work in your scenario -- if you're doing anything ingenious with the radio button content or the click handling then it may be an issue -- if not then let us know the additional constraint and I'll have a bit more of a ponder. |
|
|
The editor I'm trying to develop is a fancy way for the user to pick a direction. It would consist of 8 radio buttons and look something like: -------------------- | NW | N | NE | -------------------- | W | | E | -------------------- | SW | S | SE | --------------------
I don't think your ListBox approach would work for this because there would be multiple radio buttons per row.
Any other ideas?
Thanks. |
|
|
It's still a ListBox, just with a 3-column UniformGrid as the ItemsPanel. (Admittedly, I'm ignoring the centre here. But that's addressable by using a Grid instead of a UniformGrid and binding the Grid.Row and Grid.Column in ItemContainerStyle.) If you really don't like that approach, then the easiest alternative is probably to build a user control with a SelectedDirection dependency property (of type enum or string depending on your preference). (It has to be a DP because we have to be able to bind to it.) Then in your PropertyChangedCallback for the SelectedDirectionProperty, check the appropriate radio button (and in your radio button click handlers set the value of SelectedDirection). Your data template is now an instance of the new control, with SelectedDirection two-way data bound to Value. |
|