Layers issue using Z-Index - wpf

I've 2 controls one on top of another: border over slider. on border user can mark a segment to appear in different color on slider.
Because the border is written after slider in xaml, it appear on top of the slider. and that's ok.
My problem is, the Thumb of slider also appears under the border.
How can I set the Thumb element (belong to slider control and inside it) to appear on top of all, and also the border will appear on top of the slider?
I tried use zIndex but without success. Any idea?

In CSS:
Make sure your elements are positioned absolutely or relatively. z-index doesn't really have a play in layering unless the elements are positioned absolutely or relatively. You should then be able to set one with:
z-index: 1;
and the other with:
z-index: 2;
and get the desired result.
In WPF:
Use the syntax specified here
Here's an example:
Make sure both of your elements are in the same parent, otherwise they will be displayed in the order in which they were loaded.

Related

Why doesn't the Right and Bottom properties appears in the properties window?

I've placed an Ellipse on a Canvas. Only Canvas.Top and Canvas.Left properties are shown in Properties Window. There is no Canvas.Right or Canvas.Bottom. I'm trying to understand why some properties appear (like Top and Left) but others don't (like Bottom and Right).
PS: I know i can set Right and Bottom properties in XAML, but I'm not asking how to set those but why can't I set them in properties Window.
Thank you for reading!
The Top/Left under the layout is to adjust the position of the control in the Canvas. If you use Grid or StackPanel to contain the controls, Top/Left will disappear. In fact, BottomProperty,LeftProperty,RightProperty,TopProperty are all fields of Canvas. The Layout doesn't show all the fields, you can add it in XAML code.
You don't see them because they're not properties.
You just decided you wanted bottom and right.
That doesn't make them exist as properties.
Top and left are used as the x and y co-ordinates to position something on a canvas.
Thus they're fairly important aspects and obviously necessary.
The people building the framework added those attached properties.
The bottom and right points can be calculated using height and width.
If they thought about it at all, whoever was writing the framework must have decided they weren't necessary.

How to detect background color in React

Is there a way to detect the background color at one certain point of the page dynamically? I have a website with a fixed header, and the default logo on it is white (default background is black). However, as I scroll down there are sections that have white background, so the logo would have to change colour to black.
Setting it based on scrolling position is not possible, because all sections have different heights and the height is often dependent on the content.
I have found mix-blend-color, but unfortunately its support is pretty bad across browsers. Also tried numerous npm packages, but none of them seem to pick up the background colour.
Is there another way to dynamically change the logo color without getting the background color?
Answer 1
I never tried this, but I think this might lead to the answer.
You can use document.elementFromPoint.
This will retrieve the top element at some (x, y) point.
So you can set the x and y to 1px down the border of your modal ( or some place where you know that will only have element with the background color you want) and get the element.
And check, on a scroll event listener, what is the element at that position and get it's background color.
Is this a good thing to do? Maybe not, but it works and it have good support across browsers.
Answer 2
Setting it based on scrolling position is not possible
Of course it's possible!
If your modal is with position absolute, what you can do is get the modal's ref and use element.getBoundingClientRect() to get it's position.
Then on each section, you also get the ref (you will have an array of section's ref) in the parent component, which knows the modal's refs and section's ref.
Then, on a scroll event, you use getBoundingClientRect on each section element and check if it's inside the modal logo.
To check if it's inside, you can simply use the top and bottom ( if the scroll is vertical).
This is harder to implement, but I think it's the way to go.

WPF Grid Lines show across childrent element with span > 1

Are there any way to make grid to not show over grid children?
I mean, I want grid lines to be visible, but when a children has rowspan or columnspan over 1, I want it to hide the grid lines.
I tried setting the children (it's a label) opacity to 1 but it didn't work.
Any help will be welcome.
No there is not. From MSDN:
Only dotted lines are available because this property is intended as a design tool to debug layout problems and is not intended for use in production quality code. If you want lines inside a Grid, style the elements within the Grid to have borders.

Take object "out of the document flow" in Silverlight, with the same effect as CSS Absolute Positioning?

When using Silverlight 4, is it possible to set an Image to an absolute position, and bring it out of the document flow, allowing it to be positioned freely of any grids etc?
With CSS you can set an element to use absolute positioning, and then it will be positioned absolute, based on the first relative parent above it.
I want to be able to place an Image, anywhere on the screen, above anything else on the page, but in Silverlight.
I tried absolute positioning (In the code behind) and it doesn't seem to be positioned correctly, it looks as though it defaults to both Horizontal Alignment and Vertical alignment as
"Centre"
CustomIcon.Source = new BitmapImage(new Uri("http://media.trueachievements.com/imagestore/0000149800/149834.jpg", UriKind.Absolute));
CustomIcon.SetValue(Canvas.LeftProperty, Pt.X);
CustomIcon.SetValue(Canvas.TopProperty, Pt.Y);
CustomIcon.Visibility = System.Windows.Visibility.Visible;
Pt is set correctly elsewhere (Checked this when Debugging).
The image is in the Xaml with the x:Name attribute set, and is set to Collapsed visibility by default.
Any ideas if it's possible to get the same effect I described (CSS) but using Silverlight 4?
The canvas Left and Top attached properties only have an effect if you actually add the control to an Canvas element.
Just add a Canvas element to your xaml as the last element in the "LayoutRoot" grid. You do not need to set its width or height nor should you set it Grid.Row or Column.
Now when you add items to this canvas they can be positioned anywhere.

Unwanted clipping in WrapPanel

I need to create a ListBox with the WrapPanel ItemsTemplate.
My item is displayed as a card with small top "toolbar" that is displaying dynamically on mouse over.
[ dyn. toolbar ]
[ card ]
Everything is running well except the first line.
I need to have cards very close each other. Hence the Height of the item is set to height of the card without toolbar height. Toolbar is created with Margin.Top < 0.
The problem is that toolbar is clipped by the listbox.
Do you know any techniques on how to solve this situation?
Thanks to all!
I'm not sure I fully understand your question, but if you're displaying the toolbar above the card using a negative top margin, couldn't you compensate for this by dynamically setting a positive margin on the card whenever the toolbar is shown?
Xaml would be helpful. One rule of thumb I've found is to never set the actual height or width properties of a control. Try taking out the height property and that should get rid of the clipping. You should be able to get any spacing you need figured out with Margin, Padding, or MinHeight.

Resources