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

  • SEARCH
  • Home
  • 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 6361427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:46:33+00:00 2026-05-24T23:46:33+00:00

Goal: Change the picture from picEnlarger into picXmark if there are any input data

  • 0

Goal:
Change the picture from picEnlarger into picXmark if there are any input data in the textbox txtSearch.

If no data input in the textbox then the picture picEnlarger should be displayed and picXmark should be hidden.

Problem:
I know how to do it in xaml but not in c# code.

I want to change the picture from/to visibility or hidden by using C# ONLY.

Please remember that I want to use less xaml code.

I also tried making the picture to be hidden/visible in the textbox txtSearch’s event method ( private void txtSearch_TextChanged(object sender, TextChangedEventArgs e)) with this code:

picXmark.Visibility = Visibility.Visible;
picEnlarger.Visibility = Visibility.Hidden;

Unfortunately, I retrieve this message “Object reference not set to an instance of an object”.

<TextBox Name="txtSearch" Width="143.243" TextChanged="txtSearch_TextChanged" Text="Search article" PreviewMouseLeftButtonDown="txtSearch_PreviewMouseLeftButtonDown" />
    <Image x:Name="picEnlarger" Height="14" Width="14" Source="/MediaStore;component/Bilder/search_enlarger2.gif" />
    <Image x:Name="picXmark" Height="8" Width="8" Source="/MediaStore;component/Bilder/search_xmark.gif" />
</TextBox>
  • 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-05-24T23:46:34+00:00Added an answer on May 24, 2026 at 11:46 pm

    The TextChanged event will work fine, the problem is that it’s being raised before all your controls are initialized.

    Try something like this

    private void txtSearch_TextChanged(object sender, TextChangedEventArgs e)
    {
        if (picEnlarger != null && picXmark != null)
        {
            if (txtSearch.Text == "")
            {
                picXmark.Visibility = Visibility.Visible;
                picEnlarger.Visibility = Visibility.Hidden; 
            }
            else
            {
                picXmark.Visibility = Visibility.Hidden;
                picEnlarger.Visibility = Visibility.Visible; 
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My main goal is to change the volume on one sound card based on
The main goal of my issue is to put specific colors on Donut Change.
Goal: Produce an Excel document with information from 3 associated models that is similar
My ultimate goal is to change the background of a div through clicking on
My goal: Mousehover a link, have a certain element on the page change the
How do I change the log path of syslog daemon during runtime? My goal
My goal is to change the onclick attribute of a link. I can do
I have a little problem with a work item. My goal is to change
My ultimate goal is to change the source of the information in this tutorial
My goal is to set a background picture for each page. Consider this structure...

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.