mahapps.metro 相关问题

MahApps.Metro是一个用于创建Metro风格的WPF-Apps的工具包。它还包括一些基于Windows Phone和Windows 8 Apps概念的自定义控件。此外,它的OpenSource因此可以免费使用

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

自定义日期选择器:如何更改图标图像并单击代码隐藏上的文本框打开弹出窗口?

这是我的自定义日期选择器: 这是我的自定义日期选择器: <customcontrols:CustomDatePicker x:Name="DataCreazione" SelectedDate="{Binding DataCreazione, StringFormat={}{0:dd/MM/yyyy}}" controls:TextBoxHelper.Watermark="Data Creazione" Cursor="Hand" BorderThickness="0" SelectedDateFormat="Short" Margin="0,0,0,0" Grid.ColumnSpan="3" Grid.Row="1" /> 我将此模板应用于后面的代码: using System.Windows; using System.Windows.Controls; using System.Windows.Input; namespace Client.customcontrols { public class CustomDatePicker : DatePicker { public override void OnApplyTemplate() { base.OnApplyTemplate(); if (Template.FindName("PART_TextBox", this) is TextBox textbox) { textbox.IsReadOnly = true; textbox.Cursor = Cursors.Hand; textbox.PreviewMouseLeftButtonDown += PreviewMouseLeftButtonDown_Click; } if (Template.FindName("PART_Button", this) is Button button) { button.Visibility = Visibility.Hidden; } } private void PreviewMouseLeftButtonDown_Click(object sender, System.Windows.Input.MouseButtonEventArgs e) { IsDropDownOpen = true; } } } 我愿意: 而不是隐藏图标,我想更改它的图像(使用PackIconFontAwesome的CalendarAltSolid),大小16x16,边距0,0,8,0 单击文本框后,单击图标具有相同的行为(弹出窗口打开,在我选择日期之前保持打开状态);相反,使用 PreviewMouseLeftButtonDown,它似乎会保持弹出窗口打开,直到我按下鼠标左键单击,一旦其“向上”,弹出窗口就会消失 你能帮我解决这个问题吗? 您始终可以为Button定义自定义模板,例如: <customcontrols:CustomDatePicker x:Name="DataCreazione" SelectedDate="{Binding DataCreazione, StringFormat={}{0:dd/MM/yyyy}}" controls:TextBoxHelper.Watermark="Data Creazione" Cursor="Hand" BorderThickness="0" SelectedDateFormat="Short" Margin="0,0,0,0" Grid.ColumnSpan="3" Grid.Row="1" > <customcontrols:CustomDatePicker.Resources> <ControlTemplate x:Key="ButtonTemplate" TargetType="Button"> <Grid Background="Silver"> <iconPacks:PackIconControl Kind="{x:Static iconPacks:PackIconFontAwesomeKind.CalendarAltSolid}" Width="24" Height="24" /> </Grid> </ControlTemplate> </customcontrols:CustomDatePicker.Resources> </customcontrols:CustomDatePicker> if (Template.FindName("PART_Button", this) is Button button) { button.Template = FindResource("ButtonTemplate") as ControlTemplate; }

回答 1 投票 0

是否可以将 MahApps 的 TextBoxHelper 应用于 ScrollViewer?

我正在构建一个 WPF 应用程序,其中有一个 TextBox。要对其应用圆角,在这里我读到我需要使用边框内的 ScrollViewer 创建特定的样式。到目前为止一切顺利,b...

回答 1 投票 0

Mahapps Metro - Expander:将 LayoutTrasform 应用到标题更改样式

在使用 Mahapps Metro 的 WPF 应用程序中,我想在右侧使用 Expander。 为了防止 Expander 在折叠时占用太多空间,我想将 layoutTrasform 应用于其标题。

回答 1 投票 0

WPF 应用程序退出而不保存数据,尽管没有抛出异常

我有一个使用 MahApps.Metro 的 WPF 应用程序,并带有一个标题栏关闭按钮来关闭该应用程序。我的目标是在应用程序关闭时将记录存储在 Azure 存储帐户中。我已经

回答 1 投票 0

WPF 绑定在 MahApps.Metro 中出现一些错误,但它可以运行

**在我的xaml中:** **在我的xaml中:* * <! -- Items --> <Controls: HamburgerMenu. ItemsSource> <Controls: HamburgerMenuItemCollection> <Controls: HamburgerMenuItem Command="{Binding LinkViewModel. isMVIRCommand}" Label="WVIR"></Controls: HamburgerMenuItem> <Controls: HamburgerMenuItem Command="{Binding LinkViewModel. isTemperatureCommand}" Label="temperature"></Controls: HamburgerMenuItem> </Controls: HamburgerMenuItemCollection> </Controls: HamburgerMenu. ItemsSource> **In my LinkViewModel: ** public DelegateCommand isMVIRCommand { get; set; } public DelegateCommand isTemperatureCommand { get; set; } isMVIRCommand = new DelegateCommand(isMVIR); isTemperatureCommand = new DelegateCommand(ChangeToTemperature); private void ChangeToTemperature() { isMV = "Collapsed"; isIR = "Collapsed"; isTemperature = "Visible"; } private void isMVIR() { isMV = "Visible"; isIR = "Collapsed"; isTemperature = "Collapsed"; } **follow it's wrong: ** LinkViewModel. isMVIRCommand HamburgerMenuItem. Command ICommand FrameworkElement or FrameworkContentElement can't find the target element management. LinkViewModel. IsTemperatureCommand HamburgerMenuItem.Com and ICommand FrameworkElement or can't find the target element management FrameworkContentElement. 我确信它已经在 LinkViewModel 中 Binding 了,但是当我运行我的项目时,它可以按照我的预期运行,但是我的 wpf 设计器搞错了我。希望有人能帮我找出问题所在 我知道我可以运行该项目的原因,但我的wpf设计师对我有误解。请阅读我的代码。 <Controls:HamburgerMenuItem Command="{Binding DataContext.LinkViewModel.isMVIRCommand, RelativeSource={RelativeSource AncestorType={x:Type Controls:MetroWindow}}}" Label="WVIR"/> <Controls:HamburgerMenuItem Command="{Binding DataContext.LinkViewModel.isTemperatureCommand, RelativeSource={RelativeSource AncestorType={x:Type Controls:MetroWindow}}}" Label="temperature"/> 我添加了RelativeSource={RelativeSource AncestorType={x:Type Controls:MetroWindow}}。他们告诉wpf设计器在可以找到MetroWindow时搜索设计器树。在我的情况下,我的MetroWindow DataContext已设置为MainWindowViewModel ,而我的LinkViewModel是MainWindowModel中的一个元素,所以可以在WPF设计器中找到它

回答 1 投票 0

按钮奇怪的背景结束了?

我正在使用这个按钮: ... 我正在用这个Button: <Button Name="buttonAttiva" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,560,0,0"> <TextBlock Text="Attiva" /> 就是这样的风格: <Style TargetType="{x:Type Button}" BasedOn="{StaticResource MahApps.Styles.Button}"> <Setter Property="Width" Value="120" /> <Setter Property="Height" Value="46" /> <Setter Property="BorderThickness" Value="0" /> <Setter Property="BorderBrush" Value="Transparent" /> <Setter Property="Background" Value="#81b3d4" /> <Setter Property="Foreground" Value="#ffffff" /> <Setter Property="FontWeight" Value="Bold" /> <Setter Property="FontSize" Value="18" /> <Setter Property="FontWeight" Value="Bold" /> <Setter Property="FocusVisualStyle" Value="{x:Null}" /> <Setter Property="controls:ControlsHelper.MouseOverBorderBrush" Value="Black" /> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Orange" /> <Setter Property="BorderThickness" Value="2" /> <Setter Property="BorderBrush" Value="Black" /> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter Property="Background" Value="Orange" /> <Setter Property="BorderThickness" Value="2" /> <Setter Property="BorderBrush" Value="Black" /> </Trigger> </Style.Triggers> </Style> 正确显示为: 但是,当我用鼠标悬停时,会出现奇怪的“灰色”背景: 如何设置正确的橙色背景? 注意,我正在使用 MahApps.Metro,这可能会覆盖我猜的一些属性? 覆盖模板中使用的MahApps.Brushes.Gray8资源: <Style TargetType="{x:Type Button}" BasedOn="{StaticResource MahApps.Styles.Button}"> <Style.Resources> <SolidColorBrush x:Key="MahApps.Brushes.Gray8" Color="Orange" /> </Style.Resources> ...

回答 1 投票 0

DateTimePicker:如何删除“时间”部分?

我在 MahApps 中有一个通用的 DateTimePicker 控件: 我在 MahApps 中有一个通用的 DateTimePicker 控件: <controls:DateTimePicker x:Name="CreationDate" SelectedDateTime="{Binding CreationDate}" Width="170" Height="40" HorizontalAlignment="Left" VerticalAlignment="Top" Culture="en-US" Focusable="False" controls:TextBoxHelper.Watermark="Creation Date" controls:TextBoxHelper.UseFloatingWatermark="True" SelectedDateFormat="Short" SelectedTimeFormat="Short" /> 但是我无法隐藏时间(无论是在文本框上,还是在单击图标时打开的弹出窗口上。 如何删除它? 该控件不支持。但您可以从中创建自定义控件并覆盖 GetValueForTextBox 方法 public class CustomDateTimePicker : DateTimePicker { protected override string GetValueForTextBox() { return SelectedDate?.ToString("yyyy-MM-dd"); } } 在 XAML 中 <local:CustomDateTimePicker />

回答 1 投票 0

创建模态表单 mahapps WPF

我有一个关于 Mahapps 书店的问题 目前我正在使用,我认为它很棒,我在框架中有一个菜单和选项位置。现在,在某些形式中,我打开一个新窗口,但这并没有...

回答 1 投票 0

WPF ContextMenu Click 事件仅在背景网格的 MouseMove 事件之后触发

我有网格。在其中,我打开一个上下文菜单。当我单击一个菜单项时,会按顺序发生以下情况: (1) 触发网格的 MouseMove 事件; (2) 触发MenuItem的Click事件;并且,芬...

回答 1 投票 0

mahapps.metro 与 ExcelDNA 无法正常工作

在这里发帖看看是否有 mahapps.metro 专家有想法。让我知道“交叉发布”是否是一种不好的形式。 (或者如果你想让我在这里复制我的帖子) https://groups.google.com/forum/#!t...

回答 1 投票 0

System.Xaml.dll 中的“MS.Internal.Xaml.Parser.GenericTypeNameParser.TypeNameParserException”

当我尝试运行我的项目时,我现在收到此异常。我没有更改任何代码。 抛出异常:系统中的“MS.Internal.Xaml.Parser.GenericTypeNameParser.TypeNameParserException”...

回答 3 投票 0

MahApps IDialogCoordinator 任务被取消

我有一个带有 MS MVVM 工具包和 MahApps 的 C# WPF 应用程序。首次打开窗口时,ShowProgressAsync 将按预期工作,这意味着 xaml 端的绑定也可以正常工作。

回答 0 投票 0

未找到WPF ShowDilaog()。

我在这个窗口中使用了MahApps.Metro,当我点击一个按钮时,我想显示SecondMainWindow,但ShowDilaog方法没有找到,当我添加一个新的WPF窗口时,没有MahApps.Metro的ShowDilag()...。

回答 1 投票 -3

在没有Mahapps.Metro程序集的项目中使用MetroProgressBar控件动画。

我试图使用现有的对话框动画(线性从左到右移动点,我相信在一些windows 10对话框中也使用,如wifi连接)从MahApps.Metro ...

回答 1 投票 1

MahApps ToggleSwitch在.Net Core 3.1的2.0版本中找不到。

我正在使用最新版本的MahApps.Metro作为wpf-mvvm netcoreapp3.1应用程序。我把mvvm应用从wpf-mvvm.netframework4.7应用迁移过来。我之前的wpf-mvvm有以下问题......。

回答 1 投票 0

标签文字下载c#后直接不更新了

我正在创建一个简单的应用程序 将一个压缩文件下载到一个给定的目录中 这工作得很好,我已经设法显示下载进度并更新一个进度条。我的代码:我正在创建一个简单的应用程序,下载zip文件到一个给定的目录,这工作正常,我已经设法显示下载进度和更新的进度条。

回答 1 投票 0

在wpf .netcoreapp3.1的MahApps中,样式 "找不到资源'MetroButton'"。

我正在升级一个使用MahApps.Metro风格的wpf .netframework 4.7应用程序到wpf .netcoreapp3.1应用程序。Afterthe migration I an getting: System.Windows.Markup.XamlParseException: ''Provide value on '...

回答 1 投票 0

wpf标签控件中断选择更改

我得到了这个问题:我的应用程序有一个标签,我检查配置是否保存:如果没有保存,我显示一个消息,并强制选择标签,以管理用户在实际的标签:这是我的代码。...

回答 1 投票 0

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