Silverlight Input Controls - Day 2 - Part 12

Sign in to queue

The Discussion

  • User profile image
    james

    when retrieving the listbox item is it not simpler to write the following?
    string listBoxValue = myListBox.SelectedItem.ToString();
     

  • User profile image
    Clint

    @james: it all depends what actually is in that list box.  I could have a far more complex object in it than just a string.  In this case, what you did will work

  • User profile image
    Channel​Fennel

    20:12 "...or we could have a switch statement just as easily." - How would one use a switch statement to determine which radio button in a group is selected?

  • User profile image
    Scott

    @ChannelFennel... for Bobs example having only 2 radio buttons grouped would just be easier (like he did) to use if/else or even shorter syntax:
    string radioButtonValue = (myRadioButton1.IsChecked == true) ? "Male" : "Female";(I think thats right, although im not an experienced programmer myself so someone may correct me if i'm wrong) 
    I for a second thought that a switch statement on a radio group would off been a piece off cake, but after playing with VS and trying to get it too work was actually more tricky than i thought. but if i was to have a number of selections that i started to play around with an array then came up with this.
    RadioButton[] radio = new RadioButton[] {                radioButton1,                radioButton2,                radioButton3,                radioButton4            };
                string result = "";            foreach(RadioButton value in radio)     {                if (value.IsChecked == true)                {                    result = (string)value.Content;                }            }
    Again I'm new to C# and been a PHP Developer for about 2 years. But that is probably the best option i can think off for a few selections in a radio group.

  • User profile image
    Scott

    Sorry about the above formating... it actually looked normal as i type it on the comment box...

  • User profile image
    João

    It's really a pain to actually understand some code parts with a video size so small.
    Great tutorials though.

  • User profile image
    minompi

    Very good! Thanks

  • User profile image
    cbebop

    @João:
    Download the High quality videos, they are 720p and the code looks perfectly fine on it. Or you could just download the code from the links given below the video.

  • User profile image
    cwood

    [quote]
    Jan 28, 2011 at 7:44 AM
    It's really a pain to actually understand some code parts with a video size so small.Great tutorials though.
    [/quote]
    Yes, is there a way to get a better quality video stream? Even fullscreen I can only guess what he typed because I have past coding experience.

  • User profile image
    WayneHoggett

    [quote]
    Jan 28, 2011 at 7:44 AM
    It's really a pain to actually understand some code parts with a video size so small.Great tutorials though.


    Yes, is there a way to get a better quality video stream? Even fullscreen I can only guess what he typed because I have past coding experience.

    [/quote]

     

    See the downloads to the right? I've only used the WMV download for the duration of this course.

  • User profile image
    AMostWanted

    Hi, I just want to note that this:

    string lisboxValue = (string)(((ListBoxItem)myListBox.SelectedItem).Content);

    will work the same as:

    ListBoxItem lbi = (ListBoxItem)myListBox.SelectedItem;

    string lisboxValue = (string)lbi.Content;

    Thank you sooooooo much

  • User profile image
    svyatko

    Hi Guys,

    I am having a pretty stupid problem, and i am breaking my head on why it doesnt work.

    Its a simple thing i am sure, but it doesnt fit in my head for some reason.

     

    I have 1 text block , 3 radio buttons and 1 button. all i want is to display current radio button selection/value in the textblock by pressing a button.  here is my code so far.

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <TextBlock Height="83" HorizontalAlignment="Left" Margin="26,69,0,0" Name="resultTextBlock" Text="TextBlock" VerticalAlignment="Top" Width="330" />
                <RadioButton Content="X" Height="72" HorizontalAlignment="Left" Margin="12,166,0,0" Name="ciaRadioButton" VerticalAlignment="Top" IsChecked="True" />
                <RadioButton Content="Y" Height="72" HorizontalAlignment="Left" Margin="12,244,0,0" Name="mi6RadioButton" VerticalAlignment="Top" IsChecked="False" />
                <Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="249,457,0,0" Name="button1" VerticalAlignment="Top" Width="160" />
                <RadioButton Content="Z" Height="72" HorizontalAlignment="Left" Margin="9,322,0,0" Name="nsaRadioButton" VerticalAlignment="Top" IsChecked="False" />
            </Grid>

     

    code language="csharp"] private void button1_Click(object sender, RoutedEventArgs e)
            {
                string radioButtonValue;
                if (RadioButton1.IsChecked == true)
                {
                    radioButtonValue = "valueX";
                    resultTextBlock.Text = radioButtonValue;
                }
                else if (RadioButton2.IsChecked == true)
                {
                    radioButtonValue = "valueY";
                    resultTextBlock.Text = radioButtonValue;
                }
                else
                {
                    radioButtonValue = "valueZ";
                    resultTextBlock.Text = radioButtonValue;
                }
            }[/code]

     

    I have tried havimg Radio buttons in one group, in separate groups, but without luck.

     

    Is there anything obvious?? I might have been sitting infront of the pc for too long Smiley

     

    Any help would be appreciated.

     

    Cheers

     

  • User profile image
    Jeni

    I wanna use combobox in my application. But there is no combo box control in toolbox. Is there any other way to use combobox in our application?
    And I want one new window(i.e, Page1.xaml) to be opened after clicking on the button. How do i do that?
    Can anyone tel me?

Add Your 2 Cents