0

所以我有一个包含 TabControl 作为主要 UI 元素的窗口。我在 xaml 编辑器中默认添加了两个选项卡。当程序运行时,我想添加具有相同设置的新选项卡(但与前两个选项卡不同)。我可以通过调用来做到这一点:

URLTabContentControl documentRoot = (URLTabContentControl)Application.LoadComponent(new Uri(@"URLTabContentControl.xaml", UriKind.Relative));

它加载了我在 xaml 文件中定义的控件。基本上这就是我想在我将添加的新标签中显示的内容。在这一点上,我打电话:

TabItem ti = new TabItem();
ti.Header = "*New Capture URL " + (mainTabControl.Items.Count-1);
ti.Content = documentRoot;
int i = mainTabControl.Items.Add(ti);
mainTabControl.SelectedIndex = i;

创建新的 TabItem 会添加一个标题和通过 xaml 文件创建的控件。问题是 xaml 文件有几个不同的单选按钮组,每次我添加一个新选项卡时,现有选项卡上的单选按钮都会被取消选中。我不认为这是我的代码中的错误,所以我想知道是否有人能指出我正确的方向。其他类型的控件都没有像这样搞砸它们的状态。

这是成为 TabItems 内容的 xaml:

<UserControl x:Class="CustomCamApplication.URLTabContentControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="340" d:DesignWidth="634">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="45*" />
        <RowDefinition Height="42*" />
        <RowDefinition Height="41*" />
        <RowDefinition Height="31*" />
        <RowDefinition Height="34*" />
        <RowDefinition Height="29*" />
        <RowDefinition Height="118*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="101*" />
        <ColumnDefinition Width="105*" />
        <ColumnDefinition Width="65*" />
        <ColumnDefinition Width="45*" />
        <ColumnDefinition Width="30*" />
        <ColumnDefinition Width="88*" />
        <ColumnDefinition Width="200*" />
    </Grid.ColumnDefinitions>
    <Label Content="URL Suffix:" Height="28" HorizontalAlignment="Right" Margin="0,12,0,0" Name="urlSuffixLabel" VerticalAlignment="Top" ToolTip="Enter the part of the path that will be after the domain. http://my.domain.com:port/(enter this part)" />
    <TextBox Height="23" HorizontalAlignment="Left" Margin="6,14,0,0" Name="textBox1" VerticalAlignment="Top" Width="401" Grid.Column="1" Grid.ColumnSpan="6" />
    <Label Content="Video Source:" Height="28" HorizontalAlignment="Right" Margin="0,10,0,0" Name="videoSourceLabel" VerticalAlignment="Top" Grid.Row="1" ToolTip="Select the video source you want to use for this URL." />
    <ComboBox Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="6,10,0,0" Name="videoSourceComboBox" VerticalAlignment="Top" Width="401" Grid.Row="1" Grid.ColumnSpan="6" SelectionChanged="videoSourceComboBox_SelectionChanged" />
    <Label Content="Captured Image" Grid.Row="2" Height="28" HorizontalAlignment="Right" Margin="0,10,0,0" Name="capturedImageLabel" VerticalAlignment="Top" Width="101" />
    <Label Content="Filename Prefix:" Grid.Column="1" Grid.Row="2" Height="28" HorizontalAlignment="Right" Margin="0,10,0,0" Name="filenamePrefixLabel" VerticalAlignment="Top" Width="95" ToolTip="Enter the front part of the file names used for capture file by this video source. Example prefix1002.png" />
    <TextBox Grid.Column="2" Grid.Row="2" Height="23" HorizontalAlignment="Left" Margin="6,12,0,0" Name="filenamePrefixTextBox" VerticalAlignment="Top" Width="120" Text="capture" Grid.ColumnSpan="3" />
    <Label Content="Capture Type:" Grid.Row="5" Height="28" HorizontalAlignment="Right" Name="captureTypeLabel" VerticalAlignment="Top" Width="83" ToolTip="Store only a single image or store a series of images on the drive." />
    <RadioButton Content="Single Image" Grid.Column="1" Grid.Row="5" Height="16" HorizontalAlignment="Left" Margin="6,5,0,0" Name="captureTypeSingleRadioButton" VerticalAlignment="Top" GroupName="captureType" IsChecked="True" />
    <RadioButton Content="Series" Grid.Column="2" Grid.Row="5" Height="16" HorizontalAlignment="Left" Margin="6,5,0,0" Name="captureTypeSeriesRadioButton" VerticalAlignment="Top" GroupName="captureType" />
    <Label Content="File Format:" Grid.Column="1" Grid.Row="3" Height="28" HorizontalAlignment="Right" Margin="0,3,0,0" Name="captureFormatLabel" VerticalAlignment="Top" Width="73" ToolTip="Select the format of the stored capture files." />
    <RadioButton Content="PNG" Grid.Column="2" Grid.Row="3" Height="16" HorizontalAlignment="Left" Margin="6,8,0,0" Name="fileFormatPNGRadioButton" VerticalAlignment="Top" GroupName="fileFormat" IsChecked="True" />
    <RadioButton Content="JPG" Grid.Column="3" Grid.Row="3" Height="16" HorizontalAlignment="Left" Margin="0,8,0,0" Name="fileFormatJPGRadioButton" VerticalAlignment="Top" GroupName="fileFormat" />
    <RadioButton Content="BMP" Grid.Column="4" Grid.Row="3" Height="16" HorizontalAlignment="Left" Margin="8,8,0,0" Name="fileFormatBMPRadioButton" VerticalAlignment="Top" GroupName="fileFormat" Grid.ColumnSpan="2" />
    <CheckBox Content="Zero Pad Image Series Names" Grid.Column="5" Grid.Row="2" Height="16" HorizontalAlignment="Left" Margin="9,15,0,0" Name="filenameZeroPadCheckBox" VerticalAlignment="Top" ToolTip="Example prefix00001.png" Grid.ColumnSpan="2" />
    <Label Content="Dimensions:" Grid.Column="1" Grid.Row="4" Height="28" HorizontalAlignment="Right" Margin="0,6,0,0" Name="captureDimensionsLabel" VerticalAlignment="Top" Width="73" />
    <RadioButton Content="Source Default" Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="4" Height="16" HorizontalAlignment="Left" Margin="6,11,0,0" Name="captureDimensionsDefaultRadioButton" VerticalAlignment="Top" Width="94" GroupName="captureDimensions" IsChecked="True" ToolTip="The default capture size for the selected video source." Checked="captureDimensionsDefaultRadioButton_Checked" />
    <Label Content="Capture Interval:" Grid.Row="6" Height="28" HorizontalAlignment="Right" Margin="0,5,0,0" Name="captureIntervalLabel" VerticalAlignment="Top" Width="101" ToolTip="Enter the number of seconds between frame captures." />
    <TextBox Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="6" Height="23" HorizontalAlignment="Left" Margin="6,7,0,0" Name="catureIntervalTextBox" VerticalAlignment="Top" Width="120" Text="5" PreviewTextInput="captureIntervalTextBox_PreviewTextInput"  DataObject.Pasting="captureIntervalTextBox_Pasting"/>
    <RadioButton Content="Reported Mode" Grid.Column="4" Grid.ColumnSpan="2" Grid.Row="4" Height="16" HorizontalAlignment="Left" Margin="8,11,0,0" Name="captureDimensionsSourceReportedRadioButton" VerticalAlignment="Top" GroupName="captureDimensions" ToolTip="Select a mode from one reported by the device." Checked="captureDimensionsSourceReportedRadioButton_Checked" />
    <ComboBox Grid.Column="6" Grid.Row="4" Height="23" HorizontalAlignment="Left" Margin="0,6,0,0" Name="reportedModeComboBox" VerticalAlignment="Top" Width="174" IsEnabled="False" />
</Grid>
</UserControl>
4

1 回答 1

0

假设您的URLTabContentControl控件上有 3 组单选按钮,标题为 Group1、Group2 和 Group3。TabItem当您基于该实例动态创建一个时URLTabContentControl,还有另一组单选按钮,这些单选按钮已在您的初始组定义上扩展。这 3 组并不孤立于每个实例本身。

测试该理论的一种方法是在您的控件上保留一组单选按钮URLTabContentControl并删除组名并让框架处理默认行为;它现在应该可以按预期工作,因为没有与单选按钮绑定的明确组名URLTabContentControl

于 2010-12-25T03:53:54.023 回答