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 9028139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:54:50+00:00 2026-06-16T06:54:50+00:00

I have this code: namespace Test { public partial class SearchField : UserControl {

  • 0

I have this code:

namespace Test
{
    public partial class SearchField : UserControl
    {
        public SearchStrategy Strategy { get; set; }
        public SearchField() { InitializeComponent(); }
    }

    public class TextToTipConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            SearchStrategy Strategy = // How do I get reference to SearchField.Strategy from here?

            return Strategy.parseInput<string> (value.ToString(), (first, inp) => Strategy.tipMap.ContainsKey(first) && inp.Length == 1 ? first + Strategy.tipMap[first] : "", AppResources.GeneralSearchTip);
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

Code in XAML:

<UserControl.Resources>
        <controls:TextToTipConverter x:Key="TextToTip" />
</UserControl.Resources>
...
<TextBox x:Name="Search" Grid.Column="0" Canvas.ZIndex="1" 
                 Style="{StaticResource SearchBoxStyle}" Foreground="{StaticResource PhoneForegroundBrush}" />

<TextBox x:Name="Tip" Grid.Column="0" Canvas.ZIndex="0" IsReadOnly="True"
                 Style="{StaticResource SearchBoxStyle}" Opacity="0.5" Foreground="{StaticResource PhoneAccentBrush}"
                 Text="{Binding ElementName=Search, Converter={StaticResource TextToTip}, Path=Text}" />

SearchField‘s SearchStrategy Strategy has some methods and fields that I need to access from TextToTipConverter.
How can I get to it?

  • 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-16T06:54:51+00:00Added an answer on June 16, 2026 at 6:54 am

    SearchField.xaml is the view and SearchField.xaml.cs is the code behind. You can read information about MVVM, databinding and ViewModel on msdn.
    You can make a class called ViewModel on which you will bind your data. For instance, imagine the following class :

    public class SearchViewModel : INotifyPropertyChanged
    {
        public string Text { get; set; }
        public SearchStrategy Strategy { get; set; }
    }
    

    Your SearchField.xaml.cs will be :

    public partial class SearchField : UserControl
    {
        private SearchViewModel viewModel;
    
        public SearchField() 
        {
            this.viewModel = new SearchViewModel ();
            this.DataContext = this.viewModel;
        }
    }
    

    Now in your xaml,

    TextBox x:Name="Search" Text="{Binding Text}"
    

    will bind the data in the viewModel with the TextBox
    And you will be able to do :

    TextBox x:Name="Tip" Text="{Binding, Converter={StaticResource TextToTip}, Path=Text}"
    

    In the converter, the parameter named value will be your view model on which you can get properties :

    SearchViewModel vm = (SearchViewModel) value;
    vm.Strategy;
    vm.Text
    

    I don’t know if i’m clear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code #include <iostream> using namespace std; class Test{ public: int a;
I have the following code: using System.Configuration; namespace test { public partial class MyService
I have this code (C#): using System.Collections.Generic; namespace ConsoleApplication1 { public struct Thing {
Suppose I have code segment namespace Test { public delegate void StaticticsDelegate(object sender,EventArgs e);
I have this class to run functions in some amount of time: namespace Test
I have this custom wpf user control: ShowCustomer.xaml: <UserControl x:Class=TestControlUpdate2343.Controls.ShowCustomer xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <Grid> <TextBlock
What do I have to do to get this code work? I simply want
This is my code: public class RegularPolygon { public int VertexCount; public double SideLength;
I have this code <div id=main style=background:#aaaaaa;float:left;height:160px;margin:5px;position:relative;display:block;width:630px;> <div id=1 class=item style=background:#ffaacc;float:left;width:200px;height:150px;margin:5px;position:absolute;left:0px;top:0px;> </div> <div id=2
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);

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.