我正在编写一个应用程序,我拥有所有的逻辑,但是从前端角度来看,我还不是很熟悉。如何在app.xaml中全局设置文本框的属性[C#]
我已经学习如何设置所有按钮的全局设计。我试图做文本框的方式也一样。事实上,风格是应用的,但我不能插入任何文本到这个风格应用后的文本框... 我该如何解决它?问题是什么 ?有人会建议我什么是错的?
我想要做的只是在所有文本框和按钮周围制作红色细边框,而有人则将鼠标放在它们上方。还有一个组合框,我想以相同的风格进行操作。
这是我的App.xaml代码:
<Application x:Class="Application.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Application"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
CornerRadius="2"
BorderThickness="2"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FF0000" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="TextBox">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<!--<Setter Property="Foreground" Value="#000000"/>-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border Name="textbox"
CornerRadius="2"
BorderThickness="2"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="textbox" Property="BorderBrush" Value="#FF0000" />
<!--<Setter Property="Foreground" Value="#FF0000"/>-->
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
</Application>
编辑:按钮的方式
正常工作!编辑2:
我试图在我的方式修复组合框,但是与ControlTemplate的任何组合都不ScrollViewer已成功。这是我的应用程序中唯一缺乏的组件。我已阅读并尝试了许多解决方案,例如这样一个例如:How to style ComboBox Background on Mouse Hover?
因此,我想请求解决方案。由于我专注于编程的逻辑部分,所以对于更复杂的xaml部分的全面理解对于我来说并不重要,因为它只是突出显示了组合框。 我想要一个组合框,它改变了颜色边界,而鼠标是红色的,其余的组合框应保持标准。只有这一个属性。我如何快速改变它?
您能否提供使用此样式的文本框示例? – osmanraifgunes
1月 - 您可能想将您的“编辑2”作为单独的帖子,因为您的原始问题(文本框)已被标记为已回答,并且组合框问题是不同的。 –