I am using a WPF tab control to present separate repeated instances of a user control. i.e. Tab1 for Item1 settings, Tab2 for Item2 settings, and so on.
It appears that the radio button group names are being shared between tabs. What is going on?
Simple example:
A window contains tabs. Each tab contains a user control.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lib="clr-namespace:WpfApplication1"
Title="Window1" Height="300" Width="300">
<Grid>
<TabControl Margin="0,0,0,100" Name="tabControl1">
<TabItem Header="tabItem1" Name="tabItem1">
<lib:UserControl1 x:Name="userControlInTab1" />
</TabItem>
<TabItem Header="tabItem2" Name="tabItem2">
<lib:UserControl1 x:Name="userControlInTab2" />
</TabItem>
</TabControl>
</Grid>
The user control is simply two radiobuttons in a group:
<UserControl x:Class="WpfApplication1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="50" Width="100">
<StackPanel>
<RadioButton GroupName="Group1" Name="radiobutton1" Content="option1" IsChecked="True" />
<RadioButton GroupName="Group1" Name="radiobutton2" Content="option2" />
</StackPanel>
If you run this app, you will see that only the radiobutton1 in the second tab is checked, despite the usercontrol defining it to always be checked at startup.
Further, setting a radiobutton as checked in code behind seems to uncheck all the radiobuttons in other tabs!
It seems like things behave fine under mouse control (i.e. tabs are independent).
Lastly, the usercontrols do seem to be separate instantiations. I have tried this with sliders on user controls, for example, and they do behave independently across tabs. As they should.
Thanks for anyone's help with this. I have searched widely to no avail. Surely I'm not the only person who has had this issue. I'm using VS2008.