wpf 相关问题

Windows Presentation Foundation或WPF是用于在基于Windows的应用程序中呈现用户界面的子系统。

INotifyDataErrorInfo 出现多个验证错误,旧消息不会消失

在 WPF 项目中,我使用 INotifyDataErrorInfo 实现验证 TextBox 输入。可能会发生多个错误。 当我输入导致多个错误的内容时,所有验证错误都是

回答 3 投票 0

如何以编程方式在 WebView2 中滚动?

我最近启动了一个 WPF 项目,该项目使用 Microsoft.Web.WebView2 来显示 PDF 文件。我希望能够以编程方式滚动浏览 PDF 文件。 我已经尝试过这个:浏览器。

回答 1 投票 0

我们如何在WPF应用程序中分离单击和双击列表视图?

我有一个WPF应用程序。有一个列表视图,每次我单击或双击时,都会触发单击事件。即使我保留单击事件,当我双击时它也会自动触发...

回答 4 投票 0

我的 XAML 和 c# 找不到彼此了

所以我有一个非常奇怪的问题。 在我的所有用户控件中,IntializeComponents() 都有一个红色的波浪线。 我在后面的代码中找不到任何命名的 XAML 组件。 一切都是红色的,但我已经

回答 1 投票 0

如何使 WPF DataGrid 显示具有绑定和 DataTemplate 的 ViewModel 集合

我只是希望显示 DataGrid 内某种列表的内容。我目前正在尝试使用 ObservableCollection<> 和 DataGrid,但这可能会改变。我如何 DataTem...

回答 2 投票 0

我可以在WPF中使用NotifyIcon吗?

我想使用 WPF 最小化应用程序到系统托盘。 “NotifyIcon”是实现此结果的唯一方法吗?如果是,在 WPF 中使用“NotifyIcon”需要哪个命名空间? 如果可能的话...

回答 3 投票 0

WPF 文本框焦点

我将焦点设置在这样的文本框上: ...

回答 1 投票 0

WPF转换器资源使不相关的UI内容消失

我已经成为 WPF 开发人员大约 10 年了,我从其中看到了很多各种形状和大小的愚蠢行为,但今天我偶然发现了一批新鲜的公牛粪便,这绝对是。 ..

回答 1 投票 0

在 WPF 中的不同控件上显示验证错误模板

我有一个包含其他控件和一个文本框的用户控件。它有一个绑定到 TextBox 文本的 Value 属性,并将 ValidatesOnDataErrors 设置为 True。 当发生验证错误时...

回答 1 投票 0

WPF 应用程序在使用 SingleBorderWindow 和 WindowChrome 时超出全屏显示器宽度

我想创建一个带有自定义工具栏/控制按钮的 WPF 应用程序。大多数来源指示您使用 WindowStyle.None 并使用 WindowChrome。这确实删除了默认的 Windows 工具栏,并且它

回答 1 投票 0

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>

回答 1 投票 0

从 MahApps.Metro 中已经自定义的样式继承的正确方法是什么?

这是我正在构建的整个应用程序的(通用)自定义按钮样式: ...</desc> <question vote="0"> <p>这是我正在构建的整个应用程序的(通用)自定义按钮样式:</p> <pre><code>&lt;Style TargetType=&#34;{x:Type Button}&#34; BasedOn=&#34;{StaticResource MahApps.Styles.Button}&#34;&gt; &lt;Setter Property=&#34;HorizontalAlignment&#34; Value=&#34;Left&#34; /&gt; &lt;Setter Property=&#34;VerticalAlignment&#34; Value=&#34;Top&#34; /&gt; &lt;Setter Property=&#34;BorderThickness&#34; Value=&#34;2&#34; /&gt; &lt;Setter Property=&#34;Background&#34; Value=&#34;Red /&gt; &lt;/Style </code></pre> <p>适用于我在应用程序上拥有的所有按钮。</p> <p>现在,对于某些特定的<pre><code>CustomNoBorderButtonStyle</code></pre>,我想继承这些实际的按钮样式属性,并<strong>添加/覆盖</strong>更多。尝试过这个:</p> <pre><code>&lt;Style x:Key=&#34;CustomNoBorderButtonStyle&#34; TargetType=&#34;{x:Type Button}&#34; BasedOn=&#34;{StaticResource MahApps.Styles.Button}&#34;&gt; &lt;Setter Property=&#34;BorderThickness&#34; Value=&#34;0&#34; /&gt; &lt;Setter Property=&#34;controls:ControlsHelper.CornerRadius&#34; Value=&#34;0&#34; /&gt; &lt;/Style&gt; </code></pre> <p>放置在视图中:</p> <pre><code>&lt;Button Name=&#34;buttonPlayPauseVideo&#34; Style=&#34;{StaticResource CustomNoBorderButtonStyle}&#34; /&gt; </code></pre> <p>但它缺少主按钮的所有样式(例如缺少红色背景)。</p> <p>这个设置有什么问题吗?</p> </question> <answer tick="false" vote="0"> <p>样式也可以基于类似的类型</p> <pre><code>&lt;Style x:Key=&#34;CustomNoBorderButtonStyle&#34; TargetType=&#34;{x:Type Button}&#34; BasedOn=&#34;{StaticResource {x:Type Button}}&#34;&gt; &lt;Setter Property=&#34;BorderThickness&#34; Value=&#34;0&#34; /&gt; &lt;Setter Property=&#34;controls:ControlsHelper.CornerRadius&#34; Value=&#34;0&#34; /&gt; &lt;/Style&gt; </code></pre> </answer> </body></html>

回答 0 投票 0

WPF 动态向类添加属性并稍后通过 BindingExtension 检索它们

我希望能够在运行时向类添加属性,并稍后通过 BindingExtension 访问这些属性,例如: 类属性持有者{ 属性=[]; } 类 PropertiesAdde...

回答 1 投票 0

如何在 .NET 8 上的 WPF 中设置 SetParent?

我想在我的 WPF 应用程序中设置 SetParent,但是当我尝试这样做时,它不起作用。我在 .NET 8 中尝试过。 我要设置父级的程序是calc.exe。 私有无效MainWindow_Loaded(

回答 1 投票 0

如何在.net 8 上的 wpf 上设置 SetParent?

我想在我的WPF应用程序中设置一个SetParent, 但当我尝试这样做时。不行,我在.net 8上试试 我要设置的程序是calc.exe。 私人无效MainWindow_Loaded(对象...

回答 1 投票 0

如何将控件绑定到运行时动态添加的属性?

我看到各种教程围绕如何将属性绑定到静态控件,即txt_box1.Text绑定到Prop1,txt_box2.Text绑定到Prop2,等等。 但如您所知,文本框或任何其他...

回答 1 投票 0

执行按钮单击时使 wpf UI 响应

在我的wpf(c#)应用程序中,当用户按下按钮时会执行一个很长的过程。当按下按钮直到执行完整的代码时,窗口冻结并且用户无法执行任何操作...

回答 7 投票 0

最后的网格行在 wpf 中显示在彼此的顶部

我在后面的代码中将行添加到网格中,但每次末尾的一些行都会显示在彼此的顶部(重叠;就好像它们位于同一行中一样)。我知道该行...

回答 2 投票 0

C# WPF MVVM 带参数实例化框架

我有一个带有 Window WINDOWCompanies 的 WPF 应用程序。在此窗口中,我有两个 Comobox 绑定到 WINDOWCompaniesVM 中的 ObservableCollections。一旦

回答 1 投票 0

以正确的顺序从另一个窗口打开和关闭 2 个窗口

我有一个WPF应用程序。它有 3 个窗口,我需要按正确的顺序打开和关闭:Worker Window、Request Window 和 User Messenger Window,为了简单起见,我们将它们命名为 Window1、Window2、Window3...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.