Is it possible to set an attribute Textfrom several TextBlockwithout calling each separately? The ability to iterate through them?
Text
TextBlock
As in the following example:
<TextBlock x:Name="textblock_a" Text="Original text"/> <TextBlock x:Name="textblock_b" Text="Original text"/>
For
<TextBlock x:Name="textblock_a" Text="Modified text"/> <TextBlock x:Name="textblock_b" Text="Modified text"/>
Probably the easiest way:
foreach(var item in new[] {textblock_a, textblock_b}) item.Text = "Modified text";
PS: I would not use the word without mentioning the attribute xaml, Text- property.
xaml
WPF's way to do this is to use bindings.
As a state HERE (a simple example), you can bind Textyour value TextBlocksto the same property.
TextBlocks
Do not forget INotifyPropertyChanged, therefore, when changing the line, everything is updated.
INotifyPropertyChanged