扩音器按钮单击

时间:2011-11-21 10:53:29

标签: c# wpf

以下是我的xaml代码。 我有两个带两个按钮的扩展器 我想要的只是单击单选按钮打开的扩展器 说收音机Button1将打开Symbol,而radioButton 2将打开Picture

    <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>

我希望我对这个问题很清楚。 提前致谢

1 个答案:

答案 0 :(得分:1)

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事件。