扩展器上的单选按钮单击

本文关键字:单击 单选按钮 扩展器 | 更新日期: 2023-09-27 18:15:21

以下是我的xaml代码。我有两个有两个按钮的扩张器我只要打开扩展器按一下单选按钮假设单选按钮1将打开符号按钮2将打开图片

    <Expander Header="Symbol" >
        <Grid>
        <Label Content="Symbol Name" Height="28" HorizontalAlignment="Left" Margin="18,19,0,0" Name="lblSymbolName" VerticalAlignment="Top" />
        <Label Content="Template" Height="28" HorizontalAlignment="Left" Margin="27,0,0,157" Name="lblTemplate" VerticalAlignment="Bottom" />
        <Label Content="Type" Height="28" HorizontalAlignment="Left" Margin="35,0,0,123" Name="lblType" VerticalAlignment="Bottom" />
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="117,58,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120">
            <ComboBoxItem Content="JPG" />
            <ComboBoxItem Content="PNG" />
        </ComboBox>
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="117,92,0,0" Name="comboBox2" VerticalAlignment="Top" Width="120" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="117,21,0,0" Name="txtSymbolName" VerticalAlignment="Top" Width="120" />
    </Grid>
</Expander>
    <Expander Header="Picture">
        <Label Content="Picture Name" Height="28" HorizontalAlignment="Left" Margin="18,19,0,0" Name="lblPictureName" VerticalAlignment="Top" />
    </Expander>
    <Grid>
        <Button Content="Cancel" Height="23" Name="cmdCancel" Width="75" Margin="180,0,18,0" />
        <Button Content="OK" Height="23" Name="cmdOk" Width="75" Margin="18,0,180,0" />
    </Grid>
</StackPanel>
我希望我把问题讲清楚了。提前感谢

扩展器上的单选按钮单击

XAML:

<StackPanel>
    <Expander Header="Symbol" Name="expS" >
        <Grid>
            <Label Content="Symbol Name" Height="28" HorizontalAlignment="Left" Margin="18,19,0,0" Name="lblSymbolName" VerticalAlignment="Top" />
            <Label Content="Template" Height="28" HorizontalAlignment="Left" Margin="27,0,0,157" Name="lblTemplate" VerticalAlignment="Bottom" />
            <Label Content="Type" Height="28" HorizontalAlignment="Left" Margin="35,0,0,123" Name="lblType" VerticalAlignment="Bottom" />
            <ComboBox Height="23" HorizontalAlignment="Left" Margin="117,58,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120">
                <ComboBoxItem Content="JPG" />
                <ComboBoxItem Content="PNG" />
            </ComboBox>
            <ComboBox Height="23" HorizontalAlignment="Left" Margin="117,92,0,0" Name="comboBox2" VerticalAlignment="Top" Width="120" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="117,21,0,0" Name="txtSymbolName" VerticalAlignment="Top" Width="120" />
        </Grid>
    </Expander>
    <Expander Header="Picture" Name="expP">
        <Label Content="Picture Name" Height="28" HorizontalAlignment="Left" Margin="18,19,0,0" Name="lblPictureName" VerticalAlignment="Top" />
    </Expander>
    <Grid>
            <StackPanel>
                <RadioButton Name="rbtnSymbol" Checked="rbtnSymbol_Checked">Symbol</RadioButton>
                <RadioButton Name="rbtnPicture" Checked="rbtnPicture_Checked">Picture</RadioButton>
                <Button Content="OK" Height="23" Name="cmdOk" Width="75" Margin="18,0,180,0" />
                <Button Content="Cancel" Height="23" Name="cmdCancel" Width="75" Margin="180,0,18,0" />
            </StackPanel>
        </Grid>
    </StackPanel>
代码:

 private void rbtnSymbol_Checked(object sender, RoutedEventArgs e)
    {
        expS.IsExpanded = true;
        expP.IsExpanded = false;
    }
    private void rbtnPicture_Checked(object sender, RoutedEventArgs e)
    {
        expS.IsExpanded = false;
        expP.IsExpanded = true;
    }

给你的扩展器Name和处理单选按钮checked事件。