0

For example i have such xaml code:

<Window x:Class="SwitchingControl.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid Grid.ColumnSpan="2">
                <StackPanel Orientation="Horizontal">
                    <RadioButton Content="First"></RadioButton>
                    <RadioButton Content="Second"></RadioButton>
                    <RadioButton Content="Third"></RadioButton>
                </StackPanel>
            </Grid>
            <Grid Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"></RowDefinition>
                    <RowDefinition Height="auto"></RowDefinition>
                    <RowDefinition Height="auto"></RowDefinition>
                    <RowDefinition Height="auto"></RowDefinition>
                    <RowDefinition Height="auto"></RowDefinition>
                    <RowDefinition Height="auto"></RowDefinition>
                    <RowDefinition Height="auto"></RowDefinition>
                    <RowDefinition Height="auto"></RowDefinition>
                </Grid.RowDefinitions>
                <Label Content="First" Grid.Row="0" ></Label>
                <Label Content="Second" Grid.Row="1"></Label>
                <Label Content="First" Grid.Row="2"></Label>
                <Label Content="Second" Grid.Row="3"></Label>
                <Label Content="Third" Grid.Row="4"></Label>
                <Label Content="Third" Grid.Row="5"></Label>
                <Label Content="Second" Grid.Row="6"></Label>
            </Grid>
        </Grid>
    </Grid>
</Window>

I need to show labels which have content First is First RadioButton is checked. Labels which have content Second if Second RadioButton is checked. The main problem that number of labels acn be 70-100. Is there some elegant easy way to implement it?

A191919
  • 3,422
  • 7
  • 49
  • 93
  • 1
    Are you binding to a viewmodel or code-behind? Where do all these labels come from? – leetibbett Sep 22 '16 at 14:55
  • @leetibbett,ViewModel – A191919 Sep 22 '16 at 14:56
  • structure of WPF suggests that even if only Radio button *first* would be chosen - all labels rowDefinition would be shown (might hide them but not remove row definition). If labels represent dynamic data - it`s better to use DataGrid with the Data Trigger (although that might be much trickier than use code behind binding). – Vladimir Sep 22 '16 at 15:02
  • Since you want both a collection of data, and to track the selected data item, I would suggest using a ListBox styled to use RadioButtons. See [this answer](http://stackoverflow.com/a/28571411/302677) for an example. – Rachel Sep 22 '16 at 15:11

0 Answers0