WPF Bind Radio Buttons To Tab Control
-
How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks
If it's not broken, fix it until it is
-
How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks
If it's not broken, fix it until it is
-
How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks
If it's not broken, fix it until it is
Personally I'd wire it up via the VM, I presume you want this done via XAML!
Never underestimate the power of human stupidity RAH
-
How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks
If it's not broken, fix it until it is
Have the Radio button
IsSelected
modify theSelectedItem
thus triggering the Tab selection to change.private void PropertyChangeHandler(object sender, PropertyChangedEventArgs e)
{
if(e.PropertyName == "IsSelected")
{
SelectedItem = sender;
}
}public object SelectedItem
{
public get {return _selectedItem;}
public set
{
if(_selecteItem == value)return;
_selecteItem = value;
RaisePropertyChange("SelectedItem");
}}
And of course have your TabControl set up to use the SelecteItem.
Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.
-
How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks
If it's not broken, fix it until it is
They don't really have the concept of "the selected radio button index" in WPF. Kind of lame. You either have to do the mapping by hand (winforms style) or pass in the hard-coded index via a command parameter. If you are trying to write "professional & re-usable" code, I'd suggest going the route that I did. Create a "RadioButtonGroup" control thats derived from ItemsControl. Your ItemsSource would be an array of strings (or whatever) and your ItemTemplate would simply be a RadioButton that sets up all the bindings for you. Then you would have bindable SelectedRadioButton and/or SelectedRadioButtonIndex properties, so on and so forth. Sounds like a bit of work (its not really), but I'm assuming you are building a generic re-usable library that you'll toss this in and use on future projects :).
-
How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks
If it's not broken, fix it until it is
In XAML you could do this by binding the tabItems IsSelected to the IsChecked from the radiobutton. See the example below (for the sake of this example I removed some attributes like Height and Margin)
<Grid> <TabControl Name="tabControl1" > <TabItem Header="tabItem1" Name="tabItem1" IsSelected="{Binding ElementName=radioButton1, Path=IsChecked, Mode=TwoWay}"> <Grid /> </TabItem> <TabItem Header="tabItem2" Name="tabItem2" IsSelected="{Binding ElementName=radioButton2, Path=IsChecked, Mode=TwoWay}"> <Grid /> </TabItem> </TabControl> <RadioButton Content="1" Name="radioButton1" IsChecked="True"/> <RadioButton Content="2" Name="radioButton2" /> </Grid>
-
How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks
If it's not broken, fix it until it is
You can always create a IValueConverter. Bind to the
TabControl
SelectedIndex
. On each RadioButton, use the ConverterParameter to pass the value that should set the RadioButton to IsChecked. The IValueConverter class is pretty straight forward.