Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am develeoping WP8 app using MVVMLight. I have 4 radio buttons and one textbox. I want textbox should be visible for first two radio buttons and for rest of the two buttons it should not be visible.How should I do that in MVVMLight?

4 radio buttons
XML
<RadioButton x:Name="rbcoldcall" Content="Prospecting (New)" BorderBrush="Black" Grid.Column="0" Grid.Row="2" Foreground="Black" Margin="0,0,0,10" HorizontalAlignment="Right" Width="205" Command="{Binding RadioBtnCommand, Mode=TwoWay}" CommandParameter="{Binding Content, ElementName=rbcoldcall}" IsChecked="false"  ></RadioButton>
                                        <!--IsChecked="{Binding AllowEdit,Mode=TwoWay, Source={StaticResource BtoVViewModel}}"-->
                                        <RadioButton x:Name="rbcoldcallf" Content="Prospecting (Follow Up)" BorderBrush="Black" HorizontalAlignment="Left" Grid.Column="1" Grid.Row="2" Foreground="Black" Width="269"  Margin="0,0,0,10" Command="{Binding RadioBtnCommand, Mode=OneWay}" CommandParameter="{Binding Content, ElementName=rbcoldcallf}" IsChecked="false"  />
                                        <RadioButton x:Name="rbenquiry" BorderBrush="Black" Content="Lead (New)" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="3" Foreground="Black" Width="205" Margin="0,0,0,10" Command="{Binding RadioBtnCommand, Mode=OneWay}" CommandParameter="{Binding Content, ElementName=rbenquiry}" IsChecked="false" />
                                        <RadioButton x:Name="rbenquiryf" BorderBrush="Black" Content="Lead (Follow Up)" HorizontalAlignment="Left" Grid.Column="1" Grid.Row="3" Foreground="Black" Width="255" Command="{Binding RadioBtnCommand, Mode=OneWay}" CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}" IsChecked="false" />
                                        <RadioButton x:Name="rbother" Content="Other" BorderBrush="Black" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="4" Foreground="Black" Width="187" Command="{Binding RadioBtnCommand, Mode=OneWay}" CommandParameter="{Binding Content, ElementName=rbother}" IsChecked="false"/>


one txt box and one list picker

XML
 <StackPanel>

 <TextBox Text="" x:Name="txtCasetitle" TextWrapping="Wrap" AcceptsReturn="True" Foreground="Black" Visibility="{Binding Path=IsChecked, Converter={StaticResource BtoVConverter}, Mode=TwoWay,ElementName=rbcoldcall}" />
                                
<toolkit:ListPicker x:Name="lpCaseTitle" Margin="12,36,10,10" Foreground="Black"  ItemsSource="{Binding ObVisitType, Mode=TwoWay}" SelectedItem="{Binding SelectedVisitType, Mode=TwoWay}" Visibility="{Binding Path=IsChecked, Converter={StaticResource BtoVConverter}, Mode=TwoWay,ElementName=rbcoldcallf}">
                                    </toolkit:ListPicker>
                                </StackPanel>


If My first and third radio button clicked then I want to Visible textbox
If second and forth radio button clicked then I want to Visible ListPicker

I have written the boolean to visible Converter

C#
public class BooleanToVisibilityConverter:IValueConverter
{

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value != null)
        {
            bool isVisible = (bool)value;
            return isVisible ? Visibility.Visible : Visibility.Collapsed;
        }
        return null;

    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return (Visibility)value == Visibility.Visible;
    }
}
Posted
Updated 21-Jul-15 23:57pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900