2016-04-12 21 views
1

Aşağıdaki konuda biraz yardım/açıklama/açıklama istiyorum: RadioButton grubu için bir etkinlik nasıl kaydedilir?

Bir Expander iç içe bir TreeView öğe var, farklı dallanma seçeneklerine dayalı barındıran RadioButton kontrolleri, aynı özellik değiştirilmesi gerekir. Radyo düğmeleri hepsi aynı gruba atanır.

<Expander x:Name="expanderInterestStructure" Header="Interest Structure" HorizontalAlignment="Left" Margin="10,138,0,0" VerticalAlignment="Top" Width="132" BorderThickness="0"> 
    <Grid Margin="0,0,10,0"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="Auto"/> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto"/> 
     </Grid.ColumnDefinitions> 
     <TreeView x:Name="inputInterestStructureSelection" Margin="0,0,-131,-177" Grid.RowSpan="2"> 
      <TreeViewItem Grid.Row="0" Grid.Column="0" Header="360"> 
       <RadioButton x:Name="_360fixed" GroupName="interestStructure" Tag="360fixed" Content="Fixed Interest" IsChecked="True"/> 
       <TreeViewItem Header="Compund Interest"> 
        <RadioButton x:Name="_360compDay" GroupName="interestStructure" Tag="360compDay" Content="Daily"/> 
        <RadioButton x:Name="_360compMonth" GroupName="interestStructure" Tag="360compMonth" Content="Monthly"/> 
        <RadioButton x:Name="_360compQuater" GroupName="interestStructure" Tag="360compQuater" Content="Quaterly"/> 
        <RadioButton x:Name="_360compYear" GroupName="interestStructure" Tag="360compYear" Content="Yearly"/> 
       </TreeViewItem> 
      </TreeViewItem> 
      <TreeViewItem Grid.Row="1" Grid.Column="0" Header="365/366"> 
       <RadioButton x:Name="_365fixed" GroupName="interestStructure" Tag="365fixed" Content="Fixed Interest"/> 
       <TreeViewItem Header="Compund Interest"> 
        <RadioButton x:Name="_365compDay" GroupName="interestStructure" Tag="365compDay" Content="Daily"/> 
        <RadioButton x:Name="_365compMonth" GroupName="interestStructure" Tag="365compMonth" Content="Monthly"/> 
        <RadioButton x:Name="_365compQuater" GroupName="interestStructure" Tag="365compQuater" Content="Quaterly"/> 
        <RadioButton x:Name="_365compYear" GroupName="interestStructure" Tag="365compYear" Content="Yearly"/> 
       </TreeViewItem> 
      </TreeViewItem> 
     </TreeView> 

    </Grid> 
</Expander> 

soru, nasıl bu grubunu ve izleyen bir olay kayıt olabilirsiniz olduğu grup üyeleri değişiklikler arasında seçim, seçilen ürün etiketi veya isme bir dize özelliğini teşkil eder mi?

Şimdiden teşekkürler!

+0

ben her radyo düğmesini bu işlemek gerekir inanıyoruz:

<RadioButton ... Checked="radioButton_Checked"/> 

İçini tüm mantığı koyabilirsiniz:

neyse, her RadioButton aynı olay işleyicisi abone olabilirsiniz Grup seviyesinde değil. AutoPostBack = "True" değerini atamanız ve yönteminizi OnCheckedChanged ile ilişkilendirmeniz gerekir. Buraya bakın: http://stackoverflow.com/questions/8095256/asp-net-radio-button-change –

cevap

1

s her RadioButton s aynı grup (GroupName="interestStructure") olarak herhangi bir grubu vardır. ,

void radioButton_Checked(object sender, RoutedEventArgs e) 
{ 
    var radioButton = (RadioButton)sender; // checked RadioButton 

    // logic 
    if(radioButton == _360CompDay) 
     button.Tag = "whatever"; 
    else if ... 
} 
İlgili konular