Windows Presentation Foundation或WPF是用于在基于Windows的应用程序中呈现用户界面的子系统。
WPF 应用程序在使用 SingleBorderWindow 和 WindowChrome 时超出全屏显示器宽度
我想创建一个带有自定义工具栏/控制按钮的 WPF 应用程序。大多数来源指示您使用 WindowStyle.None 并使用 WindowChrome。这确实删除了默认的 Windows 工具栏,并且它
MahApps Metro 上的重复按钮:如何在鼠标悬停时更改背景?
这是我的滑块: 这是我的滑块: <Slider x:Name="videoPlayerSlider" Minimum="0" Maximum="100" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Thumb.DragStarted="OnSliderDragStarted_Click" Thumb.DragDelta="OnSliderDragDelta_Drag" Thumb.DragCompleted="OnSliderDragCompleted_Click" Value="50" Height="20" Margin="0,0,0,-20"> <Slider.Template> <ControlTemplate TargetType="Slider"> <Grid> <Track x:Name="PART_Track"> <Track.DecreaseRepeatButton> <RepeatButton Style="{StaticResource CustomRepeatButtonStyle}" Command="{x:Static Slider.DecreaseLarge}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Focusable="false" /> </Track.DecreaseRepeatButton> <Track.Thumb> <Thumb Style="{StaticResource CustomThumbStyle}" /> </Track.Thumb> <Track.IncreaseRepeatButton> <RepeatButton Style="{StaticResource CustomRepeatButtonStyle}" Command="{x:Static Slider.IncreaseLarge}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Focusable="false" /> </Track.IncreaseRepeatButton> </Track> </Grid> </ControlTemplate> </Slider.Template> </Slider> 这就是应用的风格: <Style x:Key="CustomThumbStyle" TargetType="Thumb"> <Setter Property="Width" Value="10" /> <Setter Property="Height" Value="20" /> <Setter Property="Padding" Value="5" /> <Setter Property="Background" Value="Red" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Thumb"> <Grid> <Rectangle Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Fill="Green" /> <Ellipse Width="10" Height="10" Fill="Red" HorizontalAlignment="Center" VerticalAlignment="Center" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="CustomRepeatButtonStyle" TargetType="RepeatButton"> <Setter Property="Background" Value="Orange" /> <Setter Property="BorderThickness" Value="0" /> <Setter Property="controls:ControlsHelper.CornerRadius" Value="0" /> <Setter Property="controls:ItemHelper.HoverBackgroundBrush" Value="Orange" /> <Setter Property="controls:ItemHelper.HoverSelectedBackgroundBrush" Value="Orange" /> <Setter Property="controls:ItemHelper.SelectedBackgroundBrush" Value="Orange" /> <Setter Property="controls:ItemHelper.ActiveSelectionBackgroundBrush" Value="Orange" /> <Style.Triggers> <Trigger Property="IsFocused" Value="True"> <Setter Property="Background" Value="Orange" /> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Orange" /> </Trigger> </Style.Triggers> </Style> 当我将鼠标悬停在两个重复按钮上时,无法更改背景颜色: (这是鼠标悬停在右边的)。我想要“红色”而不是默认的蓝色。我需要使用哪个属性?我上面尝试过的似乎没有任何结果。 有什么线索吗? 我假设您希望两个重复按钮在“鼠标输入”值为 true 时更改边框颜色。我使用了一般样式,没有扩展你的样式,所以请记住这一点。我将发布的内容绝对是多余的,但我希望这能为您澄清很多事情。我只测试了水平滑块,根据您的描述,这是您想要的结果。该代码还包含垂直滑块,但您可以根据需要修改此模板。希望对你有帮助 <Window.Resources> <Style x:Key="RepeatButtonTransparent" TargetType="{x:Type RepeatButton}"> <Setter Property="OverridesDefaultStyle" Value="true"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="Focusable" Value="false"/> <Setter Property="IsTabStop" Value="false"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RepeatButton}"> <Rectangle Fill="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"/> </ControlTemplate> </Setter.Value> </Setter> </Style> <SolidColorBrush x:Key="SliderThumb.Static.Background" Color="#FFF0F0F0"/> <SolidColorBrush x:Key="SliderThumb.Static.Border" Color="#FFACACAC"/> <SolidColorBrush x:Key="SliderThumb.Static.Foreground" Color="#FFE5E5E5"/> <SolidColorBrush x:Key="SliderThumb.MouseOver.Background" Color="#FFDCECFC"/> <SolidColorBrush x:Key="SliderThumb.MouseOver.Border" Color="#FF7Eb4EA"/> <SolidColorBrush x:Key="SliderThumb.Pressed.Background" Color="#FFDAECFC"/> <SolidColorBrush x:Key="SliderThumb.Pressed.Border" Color="#FF569DE5"/> <SolidColorBrush x:Key="SliderThumb.Disabled.Background" Color="#FFF0F0F0"/> <SolidColorBrush x:Key="SliderThumb.Disabled.Border" Color="#FFD9D9D9"/> <SolidColorBrush x:Key="SliderThumb.Track.Background" Color="#FFE7EAEA"/> <SolidColorBrush x:Key="SliderThumb.Track.Border" Color="#FFD6D6D6"/> <ControlTemplate x:Key="SliderThumbHorizontalDefault" TargetType="{x:Type Thumb}"> <Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center"> <Path x:Name="grip" Data="M 0,0 C0,0 11,0 11,0 11,0 11,18 11,18 11,18 0,18 0,18 0,18 0,0 0,0 z" Fill="{StaticResource SliderThumb.Static.Background}" Stroke="{StaticResource SliderThumb.Static.Border}" SnapsToDevicePixels="True" Stretch="Fill" StrokeThickness="1" UseLayoutRounding="True" VerticalAlignment="Center"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/> </Trigger> <Trigger Property="IsDragging" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="SliderThumbHorizontalTop" TargetType="{x:Type Thumb}"> <Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center"> <Path x:Name="grip" Data="M 0,6 C0,6 5.5,0 5.5,0 5.5,0 11,6 11,6 11,6 11,18 11,18 11,18 0,18 0,18 0,18 0,6 0,6 z" Fill="{StaticResource SliderThumb.Static.Background}" Stroke="{StaticResource SliderThumb.Static.Border}" SnapsToDevicePixels="True" Stretch="Fill" StrokeThickness="1" UseLayoutRounding="True" VerticalAlignment="Center"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/> </Trigger> <Trigger Property="IsDragging" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="SliderThumbHorizontalBottom" TargetType="{x:Type Thumb}"> <Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center"> <Path x:Name="grip" Data="M 0,12 C0,12 5.5,18 5.5,18 5.5,18 11,12 11,12 11,12 11,0 11,0 11,0 0,0 0,0 0,0 0,12 0,12 z" Fill="{StaticResource SliderThumb.Static.Background}" Stroke="{StaticResource SliderThumb.Static.Border}" SnapsToDevicePixels="True" Stretch="Fill" StrokeThickness="1" UseLayoutRounding="True" VerticalAlignment="Center"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/> </Trigger> <Trigger Property="IsDragging" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="SliderHorizontal" TargetType="{x:Type Slider}"> <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <TickBar x:Name="TopTick" Fill="{TemplateBinding Foreground}" Height="4" Margin="0,0,0,2" Placement="Top" Grid.Row="0" Visibility="Collapsed"/> <TickBar x:Name="BottomTick" Fill="{TemplateBinding Foreground}" Height="4" Margin="0,2,0,0" Placement="Bottom" Grid.Row="2" Visibility="Collapsed"/> <Border x:Name="TrackBackground" Background="{StaticResource SliderThumb.Track.Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Height="4.0" Margin="5,0" Grid.Row="1" VerticalAlignment="center"> <Canvas Margin="-6,-1"> <Rectangle x:Name="PART_SelectionRange" Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" Height="4.0" Visibility="Hidden"/> </Canvas> </Border> <Track x:Name="PART_Track" Grid.Row="1"> <Track.DecreaseRepeatButton> <RepeatButton Command="{x:Static Slider.DecreaseLarge}" Style="{StaticResource RepeatButtonTransparent}"/> </Track.DecreaseRepeatButton> <Track.IncreaseRepeatButton> <RepeatButton Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource RepeatButtonTransparent}"/> </Track.IncreaseRepeatButton> <Track.Thumb> <Thumb x:Name="Thumb" Focusable="False" Height="18" OverridesDefaultStyle="True" Template="{StaticResource SliderThumbHorizontalDefault}" VerticalAlignment="Center" Width="11"/> </Track.Thumb> </Track> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="TickPlacement" Value="TopLeft"> <Setter Property="Visibility" TargetName="TopTick" Value="Visible"/> <Setter Property="Template" TargetName="Thumb" Value="{StaticResource SliderThumbHorizontalTop}"/> <Setter Property="Margin" TargetName="TrackBackground" Value="5,2,5,0"/> </Trigger> <Trigger Property="TickPlacement" Value="BottomRight"> <Setter Property="Visibility" TargetName="BottomTick" Value="Visible"/> <Setter Property="Template" TargetName="Thumb" Value="{StaticResource SliderThumbHorizontalBottom}"/> <Setter Property="Margin" TargetName="TrackBackground" Value="5,0,5,2"/> </Trigger> <Trigger Property="TickPlacement" Value="Both"> <Setter Property="Visibility" TargetName="TopTick" Value="Visible"/> <Setter Property="Visibility" TargetName="BottomTick" Value="Visible"/> </Trigger> <Trigger Property="IsSelectionRangeEnabled" Value="true"> <Setter Property="Visibility" TargetName="PART_SelectionRange" Value="Visible"/> </Trigger> <Trigger Property="IsKeyboardFocused" Value="true"> <Setter Property="Foreground" TargetName="Thumb" Value="Blue"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" TargetName="TrackBackground" Value="Red"/> <Setter Property="BorderBrush" TargetName="TrackBackground" Value="Red"/> </Trigger> <Style.Triggers> <Trigger Property="Orientation" Value="Vertical"> <Setter Property="Template" Value="{StaticResource SliderVertical}"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Red"/> <Setter Property="BorderBrush" Value="Red"/> </Trigger> </Style.Triggers> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="SliderThumbVerticalDefault" TargetType="{x:Type Thumb}"> <Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center"> <Path x:Name="grip" Data="M0.5,0.5 L18.5,0.5 18.5,11.5 0.5,11.5z" Fill="{StaticResource SliderThumb.Static.Background}" Stroke="{StaticResource SliderThumb.Static.Border}" Stretch="Fill"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/> </Trigger> <Trigger Property="IsDragging" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="SliderThumbVerticalLeft" TargetType="{x:Type Thumb}"> <Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center"> <Path x:Name="grip" Data="M 6,11 C6,11 0,5.5 0,5.5 0,5.5 6,0 6,0 6,0 18,0 18,0 18,0 18,11 18,11 18,11 6,11 6,11 z" Fill="{StaticResource SliderThumb.Static.Background}" Stroke="{StaticResource SliderThumb.Static.Border}" Stretch="Fill"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/> </Trigger> <Trigger Property="IsDragging" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="SliderThumbVerticalRight" TargetType="{x:Type Thumb}"> <Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center"> <Path x:Name="grip" Data="M 12,11 C12,11 18,5.5 18,5.5 18,5.5 12,0 12,0 12,0 0,0 0,0 0,0 0,11 0,11 0,11 12,11 12,11 z" Fill="{StaticResource SliderThumb.Static.Background}" Stroke="{StaticResource SliderThumb.Static.Border}" Stretch="Fill"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/> </Trigger> <Trigger Property="IsDragging" Value="true"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/> <Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="SliderVertical" TargetType="{x:Type Slider}"> <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition MinWidth="{TemplateBinding MinWidth}" Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TickBar x:Name="TopTick" Grid.Column="0" Fill="{TemplateBinding Foreground}" Margin="0,0,2,0" Placement="Left" Visibility="Collapsed" Width="4"/> <TickBar x:Name="BottomTick" Grid.Column="2" Fill="{TemplateBinding Foreground}" Margin="2,0,0,0" Placement="Right" Visibility="Collapsed" Width="4"/> <Border x:Name="TrackBackground" Background="{StaticResource SliderThumb.Track.Background}" BorderBrush="{StaticResource SliderThumb.Track.Border}" BorderThickness="1" Grid.Column="1" HorizontalAlignment="center" Margin="0,5" Width="4.0"> <Canvas Margin="-1,-6"> <Rectangle x:Name="PART_SelectionRange" Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" Visibility="Hidden" Width="4.0"/> </Canvas> </Border> <Track x:Name="PART_Track" Grid.Column="1"> <Track.DecreaseRepeatButton> <RepeatButton Command="{x:Static Slider.DecreaseLarge}" Style="{StaticResource RepeatButtonTransparent}"/> </Track.DecreaseRepeatButton> <Track.IncreaseRepeatButton> <RepeatButton Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource RepeatButtonTransparent}"/> </Track.IncreaseRepeatButton> <Track.Thumb> <Thumb x:Name="Thumb" Focusable="False" Height="20" OverridesDefaultStyle="True" Template="{StaticResource SliderThumbVerticalDefault}" VerticalAlignment="Top" Width="18"/> </Track.Thumb> </Track> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="TickPlacement" Value="TopLeft"> <Setter Property="Visibility" TargetName="TopTick" Value="Visible"/> <Setter Property="Template" TargetName="Thumb" Value="{StaticResource SliderThumbVerticalLeft}"/> <Setter Property="Margin" TargetName="TrackBackground" Value="2,5,0,5"/> </Trigger> <Trigger Property="TickPlacement" Value="BottomRight"> <Setter Property="Visibility" TargetName="BottomTick" Value="Visible"/> <Setter Property="Template" TargetName="Thumb" Value="{StaticResource SliderThumbVerticalRight}"/> <Setter Property="Margin" TargetName="TrackBackground" Value="0,5,2,5"/> </Trigger> <Trigger Property="TickPlacement" Value="Both"> <Setter Property="Visibility" TargetName="TopTick" Value="Visible"/> <Setter Property="Visibility" TargetName="BottomTick" Value="Visible"/> </Trigger> <Trigger Property="IsSelectionRangeEnabled" Value="true"> <Setter Property="Visibility" TargetName="PART_SelectionRange" Value="Visible"/> </Trigger> <Trigger Property="IsKeyboardFocused" Value="true"> <Setter Property="Foreground" TargetName="Thumb" Value="Blue"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <Style x:Key="SliderStyle1" TargetType="{x:Type Slider}"> <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="Foreground" Value="{StaticResource SliderThumb.Static.Foreground}"/> <Setter Property="Template" Value="{StaticResource SliderHorizontal}"/> <Style.Triggers> <Trigger Property="Orientation" Value="Vertical"> <Setter Property="Template" Value="{StaticResource SliderVertical}"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Red"/> <Setter Property="BorderBrush" Value="Red"/> </Trigger> </Style.Triggers> </Style> </Window.Resources> <Slider Style="{DynamicResource SliderStyle1}" x:Name="videoPlayerSlider" Minimum="0" Maximum="100" HorizontalAlignment="Stretch" VerticalAlignment="Center" Value="50" Height="20"> </Slider>
从 MahApps.Metro 中已经自定义的样式继承的正确方法是什么?
这是我正在构建的整个应用程序的(通用)自定义按钮样式: ...</desc> <question vote="0"> <p>这是我正在构建的整个应用程序的(通用)自定义按钮样式:</p> <pre><code><Style TargetType="{x:Type Button}" BasedOn="{StaticResource MahApps.Styles.Button}"> <Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="VerticalAlignment" Value="Top" /> <Setter Property="BorderThickness" Value="2" /> <Setter Property="Background" Value="Red /> </Style </code></pre> <p>适用于我在应用程序上拥有的所有按钮。</p> <p>现在,对于某些特定的<pre><code>CustomNoBorderButtonStyle</code></pre>,我想继承这些实际的按钮样式属性,并<strong>添加/覆盖</strong>更多。尝试过这个:</p> <pre><code><Style x:Key="CustomNoBorderButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource MahApps.Styles.Button}"> <Setter Property="BorderThickness" Value="0" /> <Setter Property="controls:ControlsHelper.CornerRadius" Value="0" /> </Style> </code></pre> <p>放置在视图中:</p> <pre><code><Button Name="buttonPlayPauseVideo" Style="{StaticResource CustomNoBorderButtonStyle}" /> </code></pre> <p>但它缺少主按钮的所有样式(例如缺少红色背景)。</p> <p>这个设置有什么问题吗?</p> </question> <answer tick="false" vote="0"> <p>样式也可以基于类似的类型</p> <pre><code><Style x:Key="CustomNoBorderButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> <Setter Property="BorderThickness" Value="0" /> <Setter Property="controls:ControlsHelper.CornerRadius" Value="0" /> </Style> </code></pre> </answer> </body></html>
WPF 动态向类添加属性并稍后通过 BindingExtension 检索它们
我希望能够在运行时向类添加属性,并稍后通过 BindingExtension 访问这些属性,例如: 类属性持有者{ 属性=[]; } 类 PropertiesAdde...
如何在 .NET 8 上的 WPF 中设置 SetParent?
我想在我的 WPF 应用程序中设置 SetParent,但是当我尝试这样做时,它不起作用。我在 .NET 8 中尝试过。 我要设置父级的程序是calc.exe。 私有无效MainWindow_Loaded(
如何在.net 8 上的 wpf 上设置 SetParent?
我想在我的WPF应用程序中设置一个SetParent, 但当我尝试这样做时。不行,我在.net 8上试试 我要设置的程序是calc.exe。 私人无效MainWindow_Loaded(对象...
我看到各种教程围绕如何将属性绑定到静态控件,即txt_box1.Text绑定到Prop1,txt_box2.Text绑定到Prop2,等等。 但如您所知,文本框或任何其他...
在我的wpf(c#)应用程序中,当用户按下按钮时会执行一个很长的过程。当按下按钮直到执行完整的代码时,窗口冻结并且用户无法执行任何操作...
我在后面的代码中将行添加到网格中,但每次末尾的一些行都会显示在彼此的顶部(重叠;就好像它们位于同一行中一样)。我知道该行...
我有一个带有 Window WINDOWCompanies 的 WPF 应用程序。在此窗口中,我有两个 Comobox 绑定到 WINDOWCompaniesVM 中的 ObservableCollections。一旦
我有一个WPF应用程序。它有 3 个窗口,我需要按正确的顺序打开和关闭:Worker Window、Request Window 和 User Messenger Window,为了简单起见,我们将它们命名为 Window1、Window2、Window3...
捕获 WPF 运行时 BindingExpression 错误
我们都可以在 Visual Studio 输出窗口中看到运行时 BindingExpression 错误。但是我们可以在运行的应用程序本身中捕获这些事件吗?我听说 WPF 跟踪...这有什么作用吗...
为什么我无法像在 XAML 上那样在代码后面绑定 StringFormat?
这是我的工作示例,它正确绑定了 ViewModel 并正确触发了 StringFormat 和 ValidateMaskDecimal: 这是我的工作示例,它正确绑定了 ViewModel 并正确触发 StringFormat 和 ValidateMaskDecimal: <ListBox x:Name="Difetti" ItemsSource="{Binding Difetti}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBox x:Name="Metro" controls:TextBoxHelper.Watermark="Metro" PreviewTextInput="ValidateMaskDecimal"> <TextBox.Text> <Binding Path="Metro" StringFormat="{}{0:0.0##########}"> </Binding> </TextBox.Text> </TextBox> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> 现在,如果我尝试在后面的代码中执行类似的操作(删除 ListBox,并将唯一的 TextBox 绑定到某个特定 index = 0 处的数据模型): <TextBox x:Name="Metro" controls:TextBoxHelper.Watermark="Metro" PreviewTextInput="ValidateMaskDecimal" /> var data = DataContext as ViewModelData; if (data != null && data.Difetti.Count > 0) { int difettoIndex = 0; Metro.SetBinding(TextBox.TextProperty, new Binding { Source = data, Path = new PropertyPath($"Difetti[{difettoIndex}].Metro"), StringFormat = "{}{0:0.0##########}" }); } 它会抛出 ValueStringBuilder 的 ThrowFormatError 异常: System.FormatException: '输入字符串的格式不正确。'. 我不明白为什么。 我哪里错了?代码不应该给我同样的结果吗? DataModel 上的 Metro 以这种方式配置(可空 decimal): private decimal? metro; public decimal? Metro { get { return metro; } set { SetField(ref metro, value, "Metro"); } } 字符串格式前缀的 {} 特定于 XAML。您在代码中不需要它。 当然,您可以检查在XAML中创建的字符串格式文本。 BindingExpression expression = BindingOperations.GetBindingExpression(Metro, TextBox.TextProperty); string format = expression.ParentBinding.StringFormat; Debug.WriteLine(format);
将我的数据库中的数据绑定到 DataGrid WPF C# MVC 模式
我正在使用 EF Core 和 MVC 模式来创建桌面应用程序(我知道 MVVM 更好,但我被迫在工作中使用 MVC)。如何将数据直接从数据库链接到 Projets.x 中的数据网格...
我在绘制列左对齐或居中对齐的列表视图时遇到问题。我查看了在这里或其他论坛上找到的一些解决方案,但它们似乎适用于所有公司...
我的 WPF 4.5 应用程序有一个小(但烦人)的视觉错误,其中 DataGrid 的单元格在加载时被切断: 屏幕截图的 Dropbox 链接 但是一旦你调整窗口大小(点击正方形但是......
WPF - 从 UserControl 访问 ViewModel 中的 EventHandler
我正在尝试从 MainViewModel 获取 DataGrid 的 SelectionChangedEventHandler 实现,但我不断收到错误,但如果我将 EventHandler 放在 MainWindow 内,它就可以正常工作。 错误 '
我可以通过不同的“API”DLL 仅公开一个 .NET DLL 公共类的一部分吗?
我正在设计一个 WPF 应用程序,它使用大约有 40 个公共类的 DLL。我需要将这些公开,原因有多种,包括易于数据绑定和混淆。我想要一个...
如何在 WPF 桌面应用程序中开发公共 API 对象模型,以允许从另一个 .NET 桌面应用程序进行进程外自动化
我们正在使用 Windows Presentation Foundation 开发一个大型桌面应用程序。目前,该应用程序仅供内部使用,但最终将作为商业产品出售。我现在...
我正在寻找一个允许创建 PDF 运行时的 API。它还应该允许将动态数据和表格包含到 PDF 文档中。我发现了一个名为 aspose.pdf API 的 API,它可以满足我的