locked
writing code for silverlight controls RRS feed

  • Question

  • Hi everybody at Microsoft Silverlight. NET Forums. I have just started to look at silverlight to create a stand alone version of a small desktop app that I created in visual studio 2010 (vb) and was hopeing that there may be somone that could help me out with this question. Like visual basic can you just pull the controls from the tool box into the design area and just double click, then just simply write the code you want to apply to that control or do you have to be proficiant in XAML to make the control function? I'm a "newbe" in both areas of application development and I tried writting a small piece of code for a button control but when I ran it in the Chrome browser the buton showed fine but the event assigned to the button didn't work. This is what I wrote for the control:

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
    lblMessage.Text = "Hello World"
    End Sub
    End Class

    Thursday, October 18, 2012 12:00 PM

Answers

  • Ok, here is your code. The event Click of your Button isnt handled.

    <Button Content="Button 1" Height="23" Name="Button1" Width="75" HorizontalContentAlignment="Center" />

     My Code:

    <Button Content="Button" HorizontalAlignment="Left" Click="Button_Click_1"/>

    To handle the event double click the Button or select it and go to properties->events and double click Click event.
    If you select a answer as correct and then uncheck it, I lose points T_T!. 

    Saturday, October 20, 2012 10:21 AM

All replies

  • Hello!

    Try this (using StackPanel), because i think that your button is hiding your TextBlock.

    XAML:

            <StackPanel>
                <Button Content="Button" HorizontalAlignment="Left" Click="Button_Click_1"/>
                <TextBlock x:Name="lblMessage"/>
            </StackPanel>

    C#:

        Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
            lblMessage.Text = "Hello World"
        End Sub




    Thursday, October 18, 2012 12:18 PM
  • Thanks for getting back to me iTateSLC

    much appreciated

    Kind Regards 

    Will.

    Friday, October 19, 2012 5:26 AM
  • The answer helped you?

    Friday, October 19, 2012 11:13 AM
  • Hi iTateSLC,

    It helped me a little. What I found was to get that particular piece of vb code to work was that I had to have something similar in the XMAL code which in turn triggered the vb code to work. I used the stack panel to make sure everything was kept central in the design area so nothing could hide the output of the text. Please see code attached to this message.

    d:DesignHeight="300" d:DesignWidth="400">
        <Grid x:Name="LayoutRoot" Background="White">
    
        <StackPanel>
    
            <TextBlock x:Name="lblMessage" Text="Hello World."
                       Margin="5"></TextBlock>
            
            <Button Content="Button 1" Height="23" Name="Button1" Width="75" HorizontalContentAlignment="Center" />
                
            </StackPanel>
        </Grid>
    </UserControl>

    Saturday, October 20, 2012 2:59 AM
  • Ok, here is your code. The event Click of your Button isnt handled.

    <Button Content="Button 1" Height="23" Name="Button1" Width="75" HorizontalContentAlignment="Center" />

     My Code:

    <Button Content="Button" HorizontalAlignment="Left" Click="Button_Click_1"/>

    To handle the event double click the Button or select it and go to properties->events and double click Click event.
    If you select a answer as correct and then uncheck it, I lose points T_T!. 

    Saturday, October 20, 2012 10:21 AM
  • Hi iTateSLC, Sorry about that. Didn't even realise that I'd unchecked the resolved check box

                      I was obviously unclear in my explanation of my initial question and I will re- check for you upon reply to this.

    Regards 

    Will.

    Saturday, October 20, 2012 2:56 PM