有没有办法可以在禁用的按钮中对图像进行去饱和处理?例如.ICommand.CanExecute = false?或者我需要使用单独的图像+样式/触发器
我创建了一个自定义进度条,如下所示:
<!-- Custom progress bar -->
<Style
x:Key="CopyProgressBar"
TargetType="ProgressBar">
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="ProgressBar">
<Grid>
<Border
x:Name="PART_Track"
CornerRadius="5"
BorderBrush="#BBC6C4"
BorderThickness="2" />
<Rectangle
x:Name="PART_Indicator"
Fill="#A5B2B0"
RadiusX="5"
RadiusY="5"
Margin="3"
HorizontalAlignment="Left" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
以下是它的使用方法:
<ProgressBar
x:Name="copyProgress"
Height="13"
Width="279"
Canvas.Left="158"
Canvas.Top="103"
Minimum="0"
Maximum="100"
Style="{StaticResource CopyProgressBar}" />
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但是当进度充满时,填充条的右侧会被剪裁,从而消除了我想要的圆形样式.我已经摆弄了填充,边距,最大宽度等,但我找不到防止剪裁的方法.
这是一张图片:

我需要为两种颜色之间的自定义控件的文本颜色设置动画,这两种颜色是从Brush自定义控件的两个属性中读取的.我的资源看起来像这样:
<SolidColorBrush x:Key="TextBrush">{TemplateBinding Foreground}</SolidColorBrush>
<SolidColorBrush x:Key="AltTextBrush">{TemplateBinding ForegroundAlt}</SolidColorBrush>
Run Code Online (Sandbox Code Playgroud)
现在,我正在尝试使用ColorAnimation进行动画制作:
<ColorAnimation Storyboard.TargetName="MyControlText" Storyboard.TargetProperty="Foreground" To="{StaticResource AltTextBrush}" Duration="00:00:00.3000000" />
Run Code Online (Sandbox Code Playgroud)
ColorAnimation似乎想要一个Color对象,而不是Brush我想要传递的对象.我想我可以写一个IValueConverter从画笔中获取颜色,但在我这样做之前,我想看看是否有更简单的方法来完成这项工作.这是我的问题:
- 是否有一种简单的方法可以在两个画笔资源之间设置动画,或者我是否需要提取动画的颜色?
- 如果我需要提取颜色,是IValueConverter的最佳实践吗?
- 最后,我走向正确的道路,还是有一个更简单的解决方案来解决这个问题?
谢谢你的帮助.
我正在使用Wpf应用程序.我为wpf创建了一个自定义样式DataGrid(在Wpf Toolkit中提供).只是我无法套用这一切工作正常Style的TextBox在出现上双击单元格(编辑模式)DataGridTextColumn.它显示为默认样式,与我的样式不匹配,看起来很奇怪.我已经在ComboBoxin DataGridComboBoxColumn和CheckBox所有其他控件上应用了一个样式,但是这个没有用.任何帮助PLZ !!!
我有一个控制库,这里重写了每个控件以进行自定义(附加功能)和重新设置.这些控件在整个应用程序中使用.我必须在控件库中的控件上应用此样式.这样我就可以在整个应用程序中反映出来.
我只看到了这个问题的代码解决方案.我正在寻找一个基于XAML的解决方案,我很安静,你不能把注意力集中在XAML中的UI元素上.
我发现这个旧的MSDN帖子:http://social.msdn.microsoft.com/Forums/en/wpf/thread/09dc837d-4485-4966-b45b-266727bbb90c
有我寻求的解决方案(这只是我猜的WPF)
<Grid FocusManager.FocusedElement="{Binding ElementName=listBox1}">
Run Code Online (Sandbox Code Playgroud)
是否将焦点设置为Silverlight 4 XAML中的TextBox/ListBox ?
我正在尝试为我的用户控件设置样式.UserControl位于项目"控件"中,主题位于项目"MainProject"中
<UserControl x:Class="Controls.OutputPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="OutputControl">
<!-- Style="{DynamicResource UserControlStyle}"> - I cant set the style here because the Resource Dictionary hasn't been defined yet -->
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MainProject;component/Themes/MyTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<!-- Now that the Resource Dictionary has been defined I need to set the style -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="textbox"
ScrollViewer.VerticalScrollBarVisibility="Visible"
Text="{Binding ElementName=OutputControl, Path=TextProperty}"
IsReadOnly="True"
Style="{DynamicResource OutputTextBoxStyle}"/>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud) 为什么我不能将其ActualWidth称为值,我可以在代码中使用它.
XAML:
<StackPanel>
<Button x:Name="cmdVibrate" HorizontalAlignment="Center">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.MouseEnter">
<BeginStoryboard>
<Storyboard >
<DoubleAnimation From="{Binding RelativeSource={RelativeSource Mode=Self},Path=ActualWidth}" By="200" AutoReverse="True" Duration="0:0:1" Storyboard.TargetProperty="Width"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
Mouse over me to shake
</Button>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud) 好的,这是我的滚动条样式.
<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
<Setter Property="Background" Value="#D5E0FF" />
</Style>
Run Code Online (Sandbox Code Playgroud)
如果我应用这个,毫无疑问,我的应用程序中的所有滚动条都会受到影响.
现在我在我的应用程序中有2个listview,我需要将这个样式应用于特定的列表视图,而另一个仍然是默认滚动条,任何想法?
这真让我抓狂.
谢谢.
以下是它现在的样子:

我希望ComboBoxItems的宽度与ComboBox.我已经覆盖了ComboBox和的默认模板ComboBoxItem.
ComboBoxItem风格:
<Style x:Key="{x:Type ComboBoxItem}"
TargetType="{x:Type ComboBoxItem}">
<Setter Property="SnapsToDevicePixels"
Value="true" />
<Setter Property="OverridesDefaultStyle"
Value="true" />
<Setter Property="FocusVisualStyle"
Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Border Name="Border"
Padding="2"
SnapsToDevicePixels="true">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsHighlighted"
Value="true">
<Setter TargetName="Border"
Property="Background"
Value="#9982B5D8" />
</Trigger>
<Trigger Property="IsEnabled"
Value="false">
<Setter Property="Foreground"
Value="#888888" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
ComboBox 样式:
<Style x:Key="{x:Type ComboBox}"
TargetType="{x:Type ComboBox}">
<Setter Property="SnapsToDevicePixels"
Value="true" />
<Setter Property="OverridesDefaultStyle"
Value="true" /> …Run Code Online (Sandbox Code Playgroud) 嘿,我正在尝试在WPF中设置按钮样式.我有一个基本风格:
<Style x:Key="buttonStyle" TargetType="{x:Type ButtonBase}">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate x:Name="ButtonBaseControlTemplate" TargetType="{x:Type ButtonBase}">
<Grid SnapsToDevicePixels="True">
<Border x:Name="Bd" Background="#9BC4E2" BorderBrush="Black"
BorderThickness="3,3,3,3" CornerRadius="7,7,7,7" Padding="5,5,5,5">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" x:Name="Content"
ContentSource="Content"
RecognizesAccessKey="True" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Grid>
<-- Removed triggers here -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
但我也需要使用它来切换按钮,只是为了改变IsChecked背景颜色.但是,当我尝试这样时,我无法访问边框来设置背景:
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource buttonStyle}">
</Style>
<Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource buttonStyle}">
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" Value="White"/> <-- Need to specify target name of the border here somehow -->
</Trigger>
</Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)
有什么建议?TA