U
U
Untiwe2021-04-19 14:15:50
WPF
Untiwe, 2021-04-19 14:15:50

How to search for elements in xml without a name?

There is a WPF with a grid already placed, it has the name "etalons_grid_perent"

<Grid x:Name="etalons_grid_perent" Background="#FF96B7F9" Height="346" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" MinHeight="80"/>
                    <RowDefinition Height="*" MinHeight="80"/>
                    <RowDefinition Height="*" MinHeight="80"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50*" MinWidth="100"/>
                    <ColumnDefinition Width="50*" MinWidth="100"/>
                    <ColumnDefinition Width="50*" MinWidth="100"/>
                    <ColumnDefinition Width="50*" MinWidth="100"/>
                </Grid.ColumnDefinitions>
</Grid>


The program dynamically creates elements (grids of less) from 0 to 9 and arranges them in the cells of the parent grid
Code example of one element
<Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height = "0.8*" />
                < RowDefinition Height= "1*" />
            </Grid.RowDefinitions >
            < Label Content= "EtalonName_1" VerticalAlignment= "Bottom" HorizontalAlignment= "Center" />
            < TextBox HorizontalAlignment= "Center" Grid.Row= "1" Text= "----" VerticalAlignment= "Top" Width= "80" Margin="0,10,0,0" TextAlignment= "Center" />
        </ Grid >


In the future, I want to iterate over these elements and edit/delete.
The question is, how can I select all elements by any criteria?

An example of what I need
Label[] label = etalons_grid_perent.AllChildren(Label, search_in_children = True).Filter(Content = "EtalonName_1");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cicatrix, 2021-04-19
@Untiwe

The first question: and if you add them dynamically, why don't you store references to them in an array, for example?
If for some reason you do not want to do this, the second question is - the Content tag is intended to indicate ... the content (content) of the element, but not the label (name). There is a "Name" attribute for this.
Well, like this:
.Where(l => l.Content.Contains("EtalonName"));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question