In <Window.Resources>
I have defined following style:
<Style x:Key="textBlockStyle" TargetType="TextBlock">
<Setter Property="Margin" Value="5,0,5,0"/>
</Style>
I have defined some grid where I have four TextBlocks
:
<WrapPanel>
<TextBlock Style="{StaticResource textBlockStyle}">Server</TextBlock>
<TextBlock Style="{StaticResource textBlockStyle}">IP</TextBlock>
<TextBlock Style="{StaticResource textBlockStyle}">Port</TextBlock>
<TextBlock Style="{StaticResource textBlockStyle}">Status</TextBlock>
</WrapPanel>
Problem: I need to reference the textBlockStyle
four times.
Question: Is it possible to set that style just once at in WrapPanel
or somewhere else without repeating the reference to the style?
Maybe something like:
<WrapPanel Style="{StaticResource textBlockStyle}">
<TextBlock>Server</TextBlock>
<TextBlock>IP</TextBlock>
<TextBlock>Port</TextBlock>
<TextBlock>Status</TextBlock>
</WrapPanel>
I am not searching for a global solution! I could delete that x:Key="textBlockStyle"
property, but that would affect all TextBlocks
in the Window. I need a more selective mechanism, but without that ugly code duplication.