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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:05:50+00:00 2026-05-18T10:05:50+00:00

I defined a usercontrol: <s:SurfaceUserControl x:Class=Prototype_Concept_1.CodeBox xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:s=http://schemas.microsoft.com/surface/2008> <Grid> <Viewbox> <s:SurfaceScrollViewer Margin=10,10,10,10 x:Name=scroll

  • 0

I defined a usercontrol:

<s:SurfaceUserControl x:Class="Prototype_Concept_1.CodeBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="http://schemas.microsoft.com/surface/2008">
    <Grid>

            <Viewbox>
                <s:SurfaceScrollViewer Margin="10,10,10,10"
        x:Name="scroll"
        Width="250" 
        Height="250" 
        VerticalScrollBarVisibility="Visible" 
        HorizontalScrollBarVisibility="Visible"
        CanContentScroll="True">
                    <RichTextBox 
           Name="TextInput"
            AcceptsReturn="True"
                TextChanged="TextChangedEventHandler"
            Width="350"
            ScrollViewer.VerticalScrollBarVisibility="Hidden"
            ScrollViewer.HorizontalScrollBarVisibility="Hidden">
                        <RichTextBox.Document>
                            <FlowDocument Name="flowDocument">
                            </FlowDocument>
                        </RichTextBox.Document>
                        <RichTextBox.Resources>
                            <Style TargetType="{x:Type Paragraph}">
                                <Setter Property="Margin" Value="0"/>
                            </Style>
                        </RichTextBox.Resources>
                    </RichTextBox>
                </s:SurfaceScrollViewer>
            </Viewbox>

    </Grid>
</s:SurfaceUserControl>

Then i use a TagVisualization and do a custom Hittest:

private void TagVisualizer_VisualizationAdded(object sender, TagVisualizerEventArgs e)
        {

            Point pt = e.TagVisualization.Center;

            // Perform the hit test against a given portion of the visual object tree.
           hitResultsList.Clear();

            // Set up a callback to receive the hit test result enumeration.
            VisualTreeHelper.HitTest(MainGrid,
                              null,
                              new HitTestResultCallback(MyHitTestResult),
                              new PointHitTestParameters(pt));

            // Perform actions on the hit test results list.
            if (hitResultsList.Count > 0)
            {
                Console.WriteLine("Number of hits: " + hitResultsList.Count);
                foreach (DependencyObject o in hitResultsList)
                {

                    if (e.TagVisualization is LoupeTagVisualization)
                    {
                        if (o.GetType() == typeof(Ellipse))
                        {
                            Console.WriteLine(((o as Ellipse).Tag as SourceFile).getName());

                            CodeBox cb = new CodeBox();

                            MainScatter.Items.Add(cb);



                            break;
                        }
                    }
                    else if (e.TagVisualization is BinTagVisualization)
                    {
                        Console.WriteLine("BinTagVisualization");
                        Console.WriteLine(o.GetType());
                        if (o.GetType() == typeof(CheckBox))
                        {
                            (o as CheckBox).Visibility = System.Windows.Visibility.Collapsed;
                        }
                    }
                }
            }


        }

        // Return the result of the hit test to the callback.
        public HitTestResultBehavior MyHitTestResult(HitTestResult result)
        {
            // Add the hit test result to the list that will be processed after the enumeration.
            hitResultsList.Add(result.VisualHit);

            // Set the behavior to return visuals at all z-order levels.
            return HitTestResultBehavior.Continue;
        }

The problem is, I don’t actually see the Codebox in the results, only the UI elements (grid, border, surfacescrollviewer, etc) that the Codebox is composed of. But how can I get the Codebox itself?

I set isHittestVisible to true

  • 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-18T10:05:51+00:00Added an answer on May 18, 2026 at 10:05 am

    Try setting the user control’s background to Transparent. Sometimes in WPF, a null ({x:null}, the default) background prevents hit-testability

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

Sidebar

Related Questions

I have the following WPF application <Window x:Class=Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:WpfApplication1 Title=Window1 Height=300 Width=300>
Here's the top of my usercontrol: <UserControl x:Class=MyApp.Common.Controls.Views.SimpleView xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:Framework=http://www.memoryexpress.com/UIFramework mc:Ignorable=d
Let's say I've created a UserControl with the following ContentTemplate defined in XAML: <UserControl.ContentTemplate>
I have defined an interface in C++, i.e. a class containing only pure virtual
I have defined a textbox with x:Name=txtMyTextBox inside UserControl called MyView. I've noticed that
I have the following link defined in a .NET 1.1 usercontrol that has the
I need read-access to a user-defined property of my UserControl, from within a <script>
Hi i have made my own UserControl, its a little windows explorer. i defined
I have a class Wizard which creates a wizard with pages defined in the
I have the situation where a SolidColorBrush (defined in App.xaml) cannot be resolved during

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.