A
A
Anton_repr2019-09-15 07:34:48
WPF
Anton_repr, 2019-09-15 07:34:48

How to assign a tag to another tag?

There is a tag:

<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="120" Margin="475,163,0,0" VerticalAlignment="Top" Width="133"/>

↑ This is the rectangle that should have the properties of this tag:
<Image HorizontalAlignment="Left" Height="120" Margin="194,38,0,0" VerticalAlignment="Top" Width="133"/>

Task: an image should appear in a rectangle, but I don’t want to insert an Image into a Rectangle

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cyber_roach, 2019-09-15
@cyber_roach

1) Image cannot be inserted into Rectangle. It is possible to insert an Image into a Border, as Rectangle does not have an internal "tag" Content presenter in the template.
- the fact that the Image will be located inside the Border is an absolutely normal practice, the Border element is intended for this
2) You can use the Image Brush and thereby abandon the Image element altogether, but to understand which approach to use, you need to look at the problem you are solving.
3) You obviously need to learn WPF and XAML, you operate with the wrong concepts.
Looking at your question, one gets the confident impression that you do not understand what you are doing at all.
- these are not tags, these are elements each for completely different purposes.
- the visual tree is built according to the principle not "I want", but according to certain requirements for the task
- Control, template, style, properties - you need to understand what it is and why, these are basic concepts in XAML.
Matthew McDonald's book "WPF: Windows Presentation Foundation in .NET 4.5" will answer these questions and more

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question