Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8685997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:43:23+00:00 2026-06-12T22:43:23+00:00

In Silverlight5, how to reference a user control resource – emoticon from a button_click

  • 0

In Silverlight5, how to reference a user control resource – emoticon from a button_click event?

I can access the object fine if I build it up in code behind then do the databinding that way, however using the XAML approach I get some nicer tooling. Example comes from Ch16

private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            // **HERE how do I reference the XAML emoticon object

            //emoticon.Name = "Smiley face2";
            //emoticon.Icon = new BitmapImage(new Uri("icons/happy.png", UriKind.RelativeOrAbsolute));
        }

.

<UserControl x:Class="EmoticonExample.MainPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:local="clr-namespace:EmoticonExample"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="400">
    <UserControl.Resources>
        <local:Emoticon x:Key="emoticon"
                        Name="SmileyFace"
                        Icon="icons/happy.png" />
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot"
          Margin="10"
          Background="White"
          DataContext="{StaticResource emoticon}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <TextBlock Text="Name:" />
        <TextBlock Text="Image:" Grid.Column="1" />

        <TextBox Name="myTextBox" Text="{Binding Name, Mode=TwoWay}" Grid.Row="1" />
        <Image Name="myImage" Source="{Binding Icon}" Stretch="None" Grid.Row="1" Grid.Column="1" />

        <Button Content="Button" HorizontalAlignment="Left" Margin="10,116,0,-92" Grid.Row="1" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
    </Grid>

</UserControl>

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:43:24+00:00Added an answer on June 12, 2026 at 10:43 pm

    Name your user control

    <UserControl x:Class="EmoticonExample.MainPage" 
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:local="clr-namespace:EmoticonExample" 
                 mc:Ignorable="d" 
                 x:Name="Example"
                 d:DesignHeight="300" 
                 d:DesignWidth="400"> 
    
    </UserControl
    

    Then reference it in your code behind:

    var emoticon = Example.Resources["emoticon"] as Emoticon; // Im not sure of your data type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As you know all, you can build a silverlight XAP package and reference it
I have a Silverlight user control that contains an ItemsControl that renders a StackPanel
In my Silverlight 3 user control I am showing a basic DataGrid control. I
We are trying to build a silverlight application that allows a user to stream
I'm trying to work with the LongListSelector control from the WP7 Silverlight Toolkit. It's
In short: How would I check the type of a UI user control during
I have a Silverlight user control that has an Image control within it. This
I am trying to build a library of silverlight controls where the client can
I have created successfully a wpf user control inheritance like this: <base:BaseUserControl x:Class=wpfcontrolinheritance.InheritedUserControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
I have a silverlight control which has a reference to a silverlight enabled wcf

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.