This is a migrated thread and some comments may be shown as answers.

Custom Action handling in code

2 Answers 86 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sascha
Top achievements
Rank 1
Sascha asked on 20 Dec 2018, 08:46 AM

I found the custom action to be kind of promising to add functionality to the report. But to make this really useful, we need the complete picture:

First, I added a textbox to the report and added a Custom Action to it.

Then I subscribed to the Enter, Leave and Executing events and added some code to handle them.

 

What I want to achieve:

a) Highlight the "button" simulated with the textbox when the user enters / hovers over it

b) Un-highlight when the user leaves

c) Execute something when the user clicks (this seems to be simple enough).

 

The highlighting doesn't really work. Let me show you my event handler:

 

        public void CustomAction_Enter(object sender, InteractiveActionEventArgs args)
        {
            var b = (Border)args.Element;

            b.BorderBrush = Brushes.DarkGray;
            b.Background = Brushes.Purple;
        }

 

This does something - it colors a part of the textbox purple. But it doesn't fill the entire textbox and also it overlays the text. When I investigate the Border, I see that is has no children. This is not properly working at all and I don't understand the purpose of the Border when it seems to have nothing to do with what we see in the report.

The expected behaviour is a border that matches / is the border of the text and a child in it that is the text as a textblock control.

 

How is this meant to be used?

 

Thanks,

Sascha

2 Answers, 1 is accepted

Sort by
0
Sascha
Top achievements
Rank 1
answered on 20 Dec 2018, 08:54 AM

Two screenshots that show the normal textbox and the hover state (with other colors, code below):

        public void CustomAction_Enter(object sender, InteractiveActionEventArgs args)
        {
            var b = (Border)args.Element;

            b.BorderBrush = Brushes.LightGreen;
            b.BorderThickness = new Thickness(1);

            b.Background = Brushes.LightCoral;
        }

0
Ivan Hristov
Telerik team
answered on 28 Dec 2018, 08:42 AM
Hi Sascha,

By the provided description I guess you're using the WPF Report Viewer. This viewer shows a XAML markup, provided by the reporting engine during the report rendering. In order to follow the internal report structure, the markup elements are not created the same way as they would in an ordinary WPF designer. For example, the TextBox report item is represented by a TextBlock and a Border element, which are siblings. The Border element has the same position and size as the TextBlock, but it may have a different size, depending on TextBox text alignment and associated action. We decided to build the markup this way because it's more efficient to use a TextBlock for the text content and then add a new Border element on the background on foreground for the additional features - borders, action, color, etc. I hope the explanation make sense and answers to your question why the Border doesn't actually have a child representing the text content.

In the current scenario I can suggest two approaches:
1) use a semi-transparent color as a Border's background, which will allow to see the text in the TextBlock underneath.
2) Get the actual TextBlock element by obtaining the previous sibling from the Border's parent with the following example code:
static TextBlock GetTextBlock(Border b)
{
    var parent = b.GetVisualParent<Canvas>();
    var borderIndex = parent.Children.IndexOf(b);
    return borderIndex == 0 ? null : parent.Children[borderIndex - 1] as TextBlock;
}
Once you've obtained the TextBlock, its background can be changed as needed. Please note that the size of the TextBlock and the size of the Border may differ, depending on the vertical alignment used in reporting TextBox.

Please take a look at this KB article that elaborates on the same subject, but provides more details on graphics paths and a tooltips. And finally, please have in mind that the produced markup is not intended to be modified on the client and may be changed in a future release of our product.

If you have further questions, please let us know.

Regards,
Ivan Hristov
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Sascha
Top achievements
Rank 1
Answers by
Sascha
Top achievements
Rank 1
Ivan Hristov
Telerik team
Share this question
or