WPF Button Style=StaticResource RoundedButtonStyle IsEnabled=False ToolTip=写EPC Command=Binding WriteEpcCmd ButtonContent StackPanel
要更改 TextBlock 样式,可以使用以下方法之一:
- 在应用程序的资源文件中定义样式,并在 TextBlock 中引用该样式:
<Window.Resources>
<Style x:Key="MyTextBlockStyle" TargetType="TextBlock">
<Setter Property="Foreground" Value="Red"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</Window.Resources>
<Button>
<Button.Content>
<StackPanel>
<TextBlock Style="{StaticResource MyTextBlockStyle}" Text=""
HorizontalAlignment="Left" VerticalAlignment="Bottom" />
<TextBlock Style="{StaticResource MyTextBlockStyle}" Text="EPC"
HorizontalAlignment="Right" VerticalAlignment="Top" Margin="7,-4,0,0" />
</StackPanel>
</Button.Content>
</Button>
- 直接在 TextBlock 中定义样式:
<Button>
<Button.Content>
<StackPanel>
<TextBlock Text=""
Foreground="Red" FontSize="16"
HorizontalAlignment="Left" VerticalAlignment="Bottom" />
<TextBlock Text="EPC"
Foreground="Red" FontSize="16"
HorizontalAlignment="Right" VerticalAlignment="Top" Margin="7,-4,0,0" />
</StackPanel>
</Button.Content>
</Button>
注意,在第二种方法中,样式只适用于当前的 TextBlock,而不会为其他 TextBlock 元素定义一个可重用的样式
原文地址: https://www.cveoy.top/t/topic/cvUn 著作权归作者所有。请勿转载和采集!