我正在使用WPF选项卡控件来呈现用户控件的不同重复实例。例如,Tab1用于Item1设置,Tab2用于Item2设置,等等。
似乎单选按钮组名称在选项卡之间共享。这是怎么回事?
简单示例:
一个窗口包含标签页。每个标签页包含一个用户控件。
<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>
用户控件只是一组两个单选按钮:
<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>
如果你运行这个应用程序,你会发现只有第二个选项卡中的radiobutton1被选中,尽管用户控件定义它在启动时总是被选中。
此外,在代码后台将一个radiobutton设置为选中似乎会取消其他选项卡中所有radiobutton的选中状态!
在鼠标控制下,事情似乎表现良好(即选项卡是独立的)。
最后,用户控件似乎是单独实例化的。例如,我已经尝试过在用户控件上使用滑块,它们在选项卡之间确实独立地工作。正如它们应该的那样。
感谢任何人对此的帮助。我已经广泛搜索但没有结果。肯定不是只有我遇到这个问题。我正在使用VS2008。