样式化是将可视元数据绑定到文档的过程
我在尝试实现 PrimeNg Inputnumber 元素时陷入困境:https://www.primefaces.org/primeng/showcase/#/inputnumber 根据其文档,有几个属性可以...
由于没有人回答我的问题(材质 UI 按钮在页面刷新后失去样式),我再次询问,这次包括 CodeSandbox:https://codesandbox.io/s/bold-resonance-8c8pz?file= /src/
我刚刚开始使用 MAUI,我想应用一种将在多个带有数据触发器的页面上使用的样式。这是我想要实现的目标: TestPage 包含这样的标签: 我刚刚开始使用 MAUI,我想应用一种将在多个带有数据触发器的页面上使用的样式。这是我想要实现的目标: TestPage 包含这样的标签: <Label Text="{Binding TaskStatus}" VerticalOptions="Center" HorizontalOptions="Center" Grid.Row="0" Grid.Column="0" Style="{StaticResource DefaultLabelStyle}" /> 然后 DefaultStyleResource 文件包含以下内容: <Style x:Key="DefaultLabelStyle" TargetType="Label"> <Style.Triggers> <DataTrigger TargetType="Label" Binding="{Binding TaskStatus}" Value="4"> <Setter Property="TextColor" Value="{DynamicResource Blue}" /> </DataTrigger> </Style.Triggers> </Style> 这可能吗?或者我只能以内联方式使用这样的数据触发器吗? 预先感谢! 可以通过将样式添加到应用程序的资源字典中来全局定义样式。您可以将样式代码添加到 App.xaml 文件中: <Application.Resource> <ResourceDictionary> ... <Style x:Key="DefaultLabelStyle"> ... </ResourceDictionary> </Application.Resource> 此后,您可以直接在页面中使用该样式: <Label Text="{Binding TaskStatus}" Style="{StaticResource DefaultLabelStyle}" .../> 更多信息可以参考全局样式。
我已将默认菜单控件添加到我的用户控件中。我需要设置菜单样式以删除包含图标或复选框空间的左边距。我怎样才能做到这一点? XAML: ... 我已将默认菜单控件添加到我的用户控件中。我需要设置菜单样式以删除包含图标或复选框空间的左边距。我该怎么做? XAML: <Menu> <MenuItem Header="MyMenu" FontSize="10"> <MenuItem Header="Options..." /> <MenuItem Header="About" /> </MenuItem> </Menu> 它目前的渲染方式与任何其他开箱即用的菜单控件一样: 我不希望菜单项左侧有边距或列。这通常用于图标等。 我认为这就是你所追求的(再次,使用Expression Blend来解决它,但就它显示的内容而言,它是我能得到的最简约的......并且花了很多时间来玩弄).. .您可以将以下内容放入空白 WPF 应用程序中作为示例: <Window x:Class="MenuItemWithNoIcon.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <SolidColorBrush x:Key="MenuItem.Highlight.Background" Color="#3D26A0DA"/> <SolidColorBrush x:Key="MenuItem.Highlight.Border" Color="#FF26A0DA"/> <SolidColorBrush x:Key="Menu.Disabled.Foreground" Color="#FF707070"/> <SolidColorBrush x:Key="MenuItem.Highlight.Disabled.Background" Color="#0A000000"/> <SolidColorBrush x:Key="MenuItem.Highlight.Disabled.Border" Color="#21000000"/> <SolidColorBrush x:Key="MenuItem.Selected.Border" Color="#FF26A0DA"/> <SolidColorBrush x:Key="MenuItem.Selected.Background" Color="#3D26A0DA"/> <Geometry x:Key="Checkmark">F1 M 10.0,1.2 L 4.7,9.1 L 4.5,9.1 L 0,5.2 L 1.3,3.5 L 4.3,6.1L 8.3,0 L 10.0,1.2 Z</Geometry> <SolidColorBrush x:Key="Menu.Static.Foreground" Color="#FF212121"/> <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}"> <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Height="22" SnapsToDevicePixels="true"> <Grid Margin="0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <ContentPresenter x:Name="menuHeaderContainer" ContentSource="Header" HorizontalAlignment="Stretch" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Stretch"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="Icon" Value="{x:Null}"/> <Trigger Property="IsChecked" Value="True"/> <Trigger Property="IsHighlighted" Value="True"> <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Background}"/> <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Border}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{StaticResource Menu.Disabled.Foreground}"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsHighlighted" Value="True"/> <Condition Property="IsEnabled" Value="False"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Disabled.Background}"/> <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Disabled.Border}"/> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> <SolidColorBrush x:Key="Menu.Static.Border" Color="#FF999999"/> <SolidColorBrush x:Key="Menu.Static.Background" Color="#FFF0F0F0"/> <SolidColorBrush x:Key="Menu.Static.Separator" Color="#FFD7D7D7"/> <Geometry x:Key="UpArrow">M 0,4 L 3.5,0 L 7,4 Z</Geometry> <Style x:Key="MenuScrollButton" BasedOn="{x:Null}" TargetType="{x:Type RepeatButton}"> <Setter Property="ClickMode" Value="Hover"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RepeatButton}"> <Border x:Name="templateRoot" BorderBrush="Transparent" BorderThickness="1" Background="Transparent" SnapsToDevicePixels="true"> <ContentPresenter HorizontalAlignment="Center" Margin="6" VerticalAlignment="Center"/> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter"/> <Geometry x:Key="DownArrow">M 0,0 L 3.5,4 L 7,0 Z</Geometry> <Style x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}" BasedOn="{x:Null}" TargetType="{x:Type ScrollViewer}"> <Setter Property="HorizontalScrollBarVisibility" Value="Hidden"/> <Setter Property="VerticalScrollBarVisibility" Value="Auto"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ScrollViewer}"> <Grid SnapsToDevicePixels="true"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Border Grid.Column="0" Grid.Row="1"> <ScrollContentPresenter CanContentScroll="{TemplateBinding CanContentScroll}" Margin="{TemplateBinding Padding}"/> </Border> <RepeatButton Grid.Column="0" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static ScrollBar.LineUpCommand}" Focusable="false" Grid.Row="0" Style="{StaticResource MenuScrollButton}"> <RepeatButton.Visibility> <MultiBinding ConverterParameter="0" Converter="{StaticResource MenuScrollingVisibilityConverter}" FallbackValue="Visibility.Collapsed"> <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/> </MultiBinding> </RepeatButton.Visibility> <Path Data="{StaticResource UpArrow}" Fill="{StaticResource Menu.Static.Foreground}"/> </RepeatButton> <RepeatButton Grid.Column="0" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static ScrollBar.LineDownCommand}" Focusable="false" Grid.Row="2" Style="{StaticResource MenuScrollButton}"> <RepeatButton.Visibility> <MultiBinding ConverterParameter="100" Converter="{StaticResource MenuScrollingVisibilityConverter}" FallbackValue="Visibility.Collapsed"> <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/> </MultiBinding> </RepeatButton.Visibility> <Path Data="{StaticResource DownArrow}" Fill="{StaticResource Menu.Static.Foreground}"/> </RepeatButton> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}"> <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true"> <Grid VerticalAlignment="Center"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Path x:Name="GlyphPanel" Data="{StaticResource Checkmark}" Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="3" Visibility="Collapsed" VerticalAlignment="Center"/> <ContentPresenter Grid.Column="1" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> <Popup x:Name="PART_Popup" AllowsTransparency="true" Focusable="false" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Bottom" PlacementTarget="{Binding ElementName=templateRoot}"> <Border x:Name="SubMenuBorder" BorderBrush="{StaticResource Menu.Static.Border}" BorderThickness="1" Background="{StaticResource Menu.Static.Background}" Padding="0"> <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}"> <Grid RenderOptions.ClearTypeHint="Enabled"> <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0"> <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=SubMenuBorder}" Height="{Binding ActualHeight, ElementName=SubMenuBorder}" Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/> </Canvas> <Rectangle Fill="{StaticResource Menu.Static.Separator}" HorizontalAlignment="Left" Margin="0" Width="1"/> <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="true" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/> </Grid> </ScrollViewer> </Border> </Popup> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSuspendingPopupAnimation" Value="true"> <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/> </Trigger> <Trigger Property="Icon" Value="{x:Null}"/> <Trigger Property="IsChecked" Value="true"> <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/> </Trigger> <Trigger Property="IsHighlighted" Value="True"> <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Background}"/> <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Border}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{StaticResource Menu.Disabled.Foreground}"/> <Setter Property="Fill" TargetName="GlyphPanel" Value="{StaticResource Menu.Disabled.Foreground}"/> </Trigger> <Trigger Property="ScrollViewer.CanContentScroll" SourceName="SubMenuScrollViewer" Value="false"> <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/> <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}"> <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true"> <Grid VerticalAlignment="Center"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <ContentPresenter x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/> <Path x:Name="GlyphPanel" Data="{StaticResource Checkmark}" Fill="{StaticResource Menu.Static.Foreground}" FlowDirection="LeftToRight" Margin="3" Visibility="Collapsed" VerticalAlignment="Center"/> <ContentPresenter Grid.Column="1" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="Icon" Value="{x:Null}"> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="IsChecked" Value="true"> <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="IsHighlighted" Value="True"> <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Background}"/> <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Border}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{StaticResource Menu.Disabled.Foreground}"/> <Setter Property="Fill" TargetName="GlyphPanel" Value="{StaticResource Menu.Disabled.Foreground}"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsHighlighted" Value="True"/> <Condition Property="IsEnabled" Value="False"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Disabled.Background}"/> <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Disabled.Border}"/> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> <Geometry x:Key="RightArrow">M 0,0 L 4,3.5 L 0,7 Z</Geometry> <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}"> <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Height="22" SnapsToDevicePixels="true"> <Grid Margin="-1"> <Grid.ColumnDefinitions> <ColumnDefinition MinWidth="22" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/> <ColumnDefinition Width="13"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="30"/> <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/> <ColumnDefinition Width="20"/> </Grid.ColumnDefinitions> <ContentPresenter x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/> <Border x:Name="GlyphPanel" BorderBrush="{StaticResource MenuItem.Highlight.Border}" BorderThickness="1" Background="{StaticResource MenuItem.Highlight.Background}" Height="22" Margin="-1,0,0,0" Visibility="Hidden" VerticalAlignment="Center" Width="22"> <Path x:Name="Glyph" Data="{DynamicResource Checkmark}" Fill="{StaticResource Menu.Static.Foreground}" FlowDirection="LeftToRight" Height="11" Width="9"/> </Border> <ContentPresenter Grid.Column="2" ContentSource="Header" HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/> <TextBlock Grid.Column="4" Margin="{TemplateBinding Padding}" Opacity="0.7" Text="{TemplateBinding InputGestureText}" VerticalAlignment="Center"/> <Path x:Name="RightArrow" Grid.Column="5" Data="{StaticResource RightArrow}" Fill="{StaticResource Menu.Static.Foreground}" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Center"/> <Popup x:Name="PART_Popup" AllowsTransparency="true" Focusable="false" HorizontalOffset="-2" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right" VerticalOffset="-3"> <Border x:Name="SubMenuBorder" BorderBrush="{StaticResource Menu.Static.Border}" BorderThickness="1" Background="{StaticResource Menu.Static.Background}" Padding="2"> <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}"> <Grid RenderOptions.ClearTypeHint="Enabled"> <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0"> <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=SubMenuBorder}" Height="{Binding ActualHeight, ElementName=SubMenuBorder}" Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/> </Canvas> <Rectangle Fill="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" HorizontalAlignment="Left" Margin="29,2,0,2" Width="1"/> <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="true" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/> </Grid> </ScrollViewer> </Border> </Popup> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSuspendingPopupAnimation" Value="true"> <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/> </Trigger> <Trigger Property="Icon" Value="{x:Null}"> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="IsChecked" Value="True"> <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="IsHighlighted" Value="True"> <Setter Property="Background" TargetName="templateRoot" Value="Transparent"/> <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Border}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{StaticResource Menu.Disabled.Foreground}"/> <Setter Property="Fill" TargetName="Glyph" Value="{StaticResource Menu.Disabled.Foreground}"/> <Setter Property="Fill" TargetName="RightArrow" Value="{StaticResource Menu.Disabled.Foreground}"/> </Trigger> <Trigger Property="ScrollViewer.CanContentScroll" SourceName="SubMenuScrollViewer" Value="false"> <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/> <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <Style x:Key="MenuItemStyle1" TargetType="{x:Type MenuItem}"> <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="ScrollViewer.PanningMode" Value="Both"/> <Setter Property="Stylus.IsFlicksEnabled" Value="False"/> <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}"/> <Style.Triggers> <Trigger Property="Role" Value="TopLevelHeader"> <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="Foreground" Value="{StaticResource Menu.Static.Foreground}"/> <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}"/> <Setter Property="Padding" Value="6,0"/> </Trigger> <Trigger Property="Role" Value="TopLevelItem"> <Setter Property="Background" Value="{StaticResource Menu.Static.Background}"/> <Setter Property="BorderBrush" Value="{StaticResource Menu.Static.Border}"/> <Setter Property="Foreground" Value="{StaticResource Menu.Static.Foreground}"/> <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}"/> <Setter Property="Padding" Value="6,0"/> </Trigger> <Trigger Property="Role" Value="SubmenuHeader"> <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}"/> </Trigger> </Style.Triggers> </Style> </Window.Resources> <Grid> <Menu> <MenuItem Header="File" Style="{DynamicResource MenuItemStyle1}"> <MenuItem Header="Exit" Style="{DynamicResource MenuItemStyle1}"/> </MenuItem> </Menu> </Grid> </Window> 简单快捷的方法如下。创建 ItemsPanelTemplate 资源: <ItemsPanelTemplate x:Key="MenuItemPanelTemplate"> <StackPanel Background="White"/> </ItemsPanelTemplate> 将以下MenuItem样式添加到资源中,就完成了。 <Style TargetType="{x:Type MenuItem}"> <Setter Property="ItemsPanel" Value="{StaticResource MenuItemPanelTemplate}"/> </Style> 要将相同的 Style 应用于 ContextMenu,您需要再创建一个 Style,如下所示: <Style TargetType="{x:Type ContextMenu}"> <Setter Property="ItemsPanel" Value="{StaticResource MenuItemPanelTemplate}"/> </Style> 在上下文菜单之上,您还必须添加: <ContextMenu ItemsSource="{Binding MyItems}" > <ContextMenu.ItemTemplate> <DataTemplate> <TextBlock Margin="-20,0,-40,0" Text="{Binding Name}"/> </DataTemplate> </ContextMenu.ItemTemplate> </ContextMenu> 因此它将覆盖图标空间并显示大小写文本块。这是最简单、最容易的解决方案。 这不是很直接,但您需要创建一个 MenuItemStyle,最简单的方法是通过 Expression Blend: <Menu> <MenuItem Header="MyMenu" Style="{DynamicResource MenuItemStyle1}"> <MenuItem Header="Options..." /> <MenuItem Header="About" /> </MenuItem> </Menu> 它创建了一组极其冗长的模板和样式,您需要编辑菜单项以删除网格的固定宽度第一列,然后在 SubMenuBorder ContentControl 模板中删除形成背景阴影的矩形。我附上了一个已删除边距的示例项目。 在此处下载示例项目。 这里有两个选项: 简短、简单、直接。将 ItemsPanelTemplate 设置为 MenuItem 或 ContextMenu,具体取决于您使用的菜单类型(请参阅详细信息)。 激进。从头开始重写 Menu 风格。有两种即用型: 来自 MahApps.Metro 的XAML 风格的Menu(普通菜单和ContextMenu) Jeff Wilcox 的风格启发了 MahApps 的前一个风格(link) 我的简单方法是在 ItemTemplate 中为网格使用负边距 <ContextMenu.ItemTemplate> <DataTemplate> <Grid Margin="-20,0,-40,0"><!--this part is important--> <Grid.ColumnDefinitions> <ColumnDefinition Width="20"/> <ColumnDefinition Width="1*"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding Ident}"/> <TextBlock Grid.Column="1" Text="{Binding Description}"/> </Grid> </DataTemplate> </ContextMenu.ItemTemplate> 查看完整答案这里 我正在使用 WPF Notifyicon(硬编码)并使用以下代码删除了菜单的图标部分: <Window ...> <Window.Resources> <ItemsPanelTemplate x:Key="MenuTPL"> <StackPanel Margin="-30,0,0,0" Background="White"/> </ItemsPanelTemplate> </Window.Resources> <Grid> ... <ContextMenu> <ContextMenu.Style> <Style TargetType="{x:Type ContextMenu}"> <Setter Property="ItemsPanel" Value="{StaticResource MenuTPL}"/> </Style> </ContextMenu.Style> <MenuItem Header="Exit" Click="Exit_MenuItemClick"/> </ContextMenu> ... </Grid> </Window> 要删除空格并且从不使用图标,您必须更改 MenuItem.SubmenuItemTemplateKey 的模板或 MenuItem 的模板。 如果您只需要摆脱垂直线并继续使用图标空间,请遵循此答案。 带有网格的 Windows 有我的 CustomContextMenu.xaml 作为网格资源: <Window ...> <Grid> <Grid.Resources> <ResourceDictionary Source="CustomContextMenu.xaml"/> </Grid.Resources> <Grid.ContextMenu> <ContextMenu> <MenuItem Header="Menu item 1" > <MenuItem Header="Menu item 2" > <MenuItem.Icon> <Image Source="icon.jpg"/> </MenuItem.Icon> </MenuItem> </MenuItem> <Separator Style="{StaticResource MySeparatorStyle}" /> <MenuItem IsEnabled="False" Header="Menu item 3" /> </ContextMenu> </Grid.ContextMenu> <TextBlock>test</TextBlock> </Grid> </Window> 这是我的 CustomContextMenu.xaml,它有一个 CustomSeparatorStyle 模板,可将分隔线延伸到上下文菜单的左边距。还有一个 ContextMenu 模板来隐藏垂直线。 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!-- Outer menu --> <Style TargetType="{x:Type ContextMenu}"> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="MaxWidth" Value="295" /> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ContextMenu}"> <!-- Here is where you change the border thickness to zero on the menu --> <Border x:Name="Border" Background="#CCCCC7" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" CornerRadius="0"> <Border.Effect> <DropShadowEffect Direction="135" Opacity=".8" ShadowDepth="2" Color="Black" /> </Border.Effect> <StackPanel ClipToBounds="True" IsItemsHost="True" Orientation="Vertical" /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="Border" Property="Background" Value="#F7F7F4" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- Separator --> <Style x:Key="CustomSeparatorStyle" TargetType="{x:Type Separator}"> <Setter Property="Height" Value="1" /> <Setter Property="Margin" Value="-30,5,0,5" /> <Setter Property="Background" Value="#F7F7F4" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Separator}"> <Border BorderBrush="#DADAD6" BorderThickness="1" /> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> 右侧菜单是使用上面的代码创建的。您可以注意到大小和阴影的差异。为了保留原始菜单的阴影,您必须排除 Border.Effect。 使用 RadMenuGroupItem。 RadMenuGroupItem 继承自 RadMenuItem 类,它用作 RadMenuItem 下拉列表的容器。换句话说,任何 UI 元素都可以放置在 RadMenuGroupItem 内部。默认情况下,RadMenuGroupItem 的背景颜色为白色,并且没有与 RadMenuItem 不同颜色的图标区域,因此您可以轻松地在下拉列表中使用不同大小的图标。除此之外,RadMenuGroupItem 还有一个 Header 属性,该属性显示在所有组项的顶部。 <telerik:RadMenu VerticalAlignment="Top"> <telerik:RadMenuItem Header="Shapes" /> <telerik:RadMenuItem Header="Sizes"> <telerik:RadMenuGroupItem Header="Header"> <telerik:RadMenuItem Header="Small" IconTemplate="{StaticResource IconTemplate}" IconColumnWidth="35" Height="35" /> <telerik:RadMenuItem Header="Medium" IconTemplate="{StaticResource IconTemplate}" IconColumnWidth="45" Height="45" /> <telerik:RadMenuItem Header="Large" IconTemplate="{StaticResource IconTemplate}" IconColumnWidth="55" Height="55" /> </telerik:RadMenuGroupItem> </telerik:RadMenuItem> 这就是结果: 感谢您的成功想法。对于 .net Framework 4.5 和 VS 2012,我相应地为 ContextMenu 和 MenuItem 编写了: private const double ICON_SIZE = 32; void ContextMenu_Loaded(object sender, System.Windows.RoutedEventArgs e) { if (_pointerControl.ContextMenu.Template != null) { System.Windows.Shapes.Rectangle r1 = _pointerControl.ContextMenu.Template.FindName("3_T", _pointerControl.ContextMenu) as System.Windows.Shapes.Rectangle; System.Windows.Shapes.Rectangle r2 = _pointerControl.ContextMenu.Template.FindName("4_T", _pointerControl.ContextMenu) as System.Windows.Shapes.Rectangle; System.Windows.Shapes.Rectangle r3 = _pointerControl.ContextMenu.Template.FindName("5_T", _pointerControl.ContextMenu) as System.Windows.Shapes.Rectangle; double width = Math.Max(28, ICON_SIZE+14); r1.Width = width; r2.Margin = new System.Windows.Thickness(width + 1, 2, 0, 2); r3.Margin = new System.Windows.Thickness(width + 2, 2, 0, 2); } } void mi_Loaded(object sender, System.Windows.RoutedEventArgs e) { System.Windows.Controls.MenuItem mi = sender as System.Windows.Controls.MenuItem; if (mi != null && mi.Template != null) { System.Windows.Controls.ContentPresenter cp = mi.Template.FindName("Icon", mi) as System.Windows.Controls.ContentPresenter; cp.Height = ICON_SIZE + 6; cp.Width = ICON_SIZE + 6; } }
我目前正在使用 TinyMCE 编辑器插入文本,该文本的配置与使用 CSS 的 TinyMCE 默认样式不同: 单击链接按钮时,会弹出如何插入...
如何在 sencha ex js 7 中设置 fieldLabel 颜色以在项目中将项目着色为白色作为显示字段
如何在 Sencha Ext JS 7 中将字段标签颜色设置为 color:"white" 项目中的显示字段 { 字段标签:“Inizio”, itemId: "数据Id", xtype: "显示字段...
为了将样式与 PyQt 代码的其余部分分开,我尝试使用 qss 文件进行样式设置。然而,使用它来完成所有的样式似乎很困难(如果不是不可能的话)。 什么会...
我的应用程序中有一个带有选项组的简单选择框。 沃尔沃 我的应用程序中有一个带有选项组的简单选择框。 <select> <optgroup label="Swedish Cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> </optgroup> ---- ---- ---- </select> 在浏览器中显示时,选项组标签以粗体和斜体显示;我希望它在没有任何这些样式的情况下显示。 在大多数浏览器上(在最新的 IE 和 FF 上测试),您可以仅使用 CSS 轻松更改 optgroup 的标签: select optgroup{ background: #000; color: #fff; font-style: normal; font-weight: normal; } 显然,您可以设置任何类名,而不是选择 html 标签。 顺便说一句,正如其他答案所说,仍然有很少的 CSS 选项可与选择框一起使用,并且许多网站管理员使用 user949847 给出的方法覆盖它们。但上面的代码应该足以满足您的需求。 不幸的是,选择框是少数可以使用 CSS 添加很少样式的东西之一。您通常会受限于浏览器的呈现方式。 例如,在 chrome 中看起来像这样: Firefox 中是这样的: Firefox 使用此规则设置标签样式: optgroup:before { content: attr(label); display: block; } 您可以覆盖它。 对于规避样式选项组问题的不同方法,我建议使用禁用选项。 <option disabled>[group label]</option> 您可以通过例如来尝试一下造型。 <style> [disabled] { color:#000; background-color:#CCC } </style> 您可以仅使用 CSS 来设置选择框的样式,这需要一种解决方法: 首先,用 div 包围它并给它一个类: <div class="selectStyle"> <select> <option>First Option</option> <option>Second Option</option> </select> </div> 然后确保使用 css 以某种方式设置选择元素的样式: .selectStyle select { background: transparent; width: 250px; padding: 4px; font-size: 1em; border: 1px solid #ddd; height: 25px; } 然后你设置 div 的样式: .selectStyle { width: 235px; height: 25px; overflow: hidden; background: url(yourArrow.png) no-repeat right #ccc; } 您只能为 Firefox 设置 <optgroup> 标签的样式,如下所示 optgroup[label] { color: grey; font-style: inherit; font-weight: 300; text-shadow: none } 您可以放弃使用 label 属性,并将禁用的 <option> 设置为 <optgroup> 中的第一个元素,然后设置此选项的样式。 <select> <option>1. One</option> <option>2. Two</option> <optgroup> <option disabled style="background:#dfb;color:#555;position:relative;top:-0.7em">3. Three</option> <option>3.1 Three dot one</option> <option>3.2 Three dot two</option> </optgroup> <option>4. Four</option> </select> 额外提示: 如果您本身不需要<optgroup>,则变体只是使用禁用的选项,在一定程度上将通过在列表中创建部分来视觉上模拟选项组。 出于美观原因,如果您在 optgroup 中使用禁用选项,我建议使用 position:relative;top:-0.7em 稍微向上移动它。 <style> .select2-container--bootstrap .select2-results__group { color: inherit; font-size: inherit; font-weight:bold; padding: 6px 4px; } .select2-results__group{ /* put your style here */ }
如何使用与 GitHub 完全相同的样式将 Markdown 文件导出为 PDF?
我花了一整天的时间试图弄清楚这一点,但我做不到。我找不到我正在寻找的解决方案。 我正在为进入我的项目的新开发人员准备一些 .md wiki 文档,我想...
我有一个十六进制值数组, “颜色”:[“#d5dd90”,“#e6bb45”,“#ef9770”] 我可以像这样注销这些: 颜色.forEach((值)=>{ console.log('%cABC', `
我正在寻找构建一个断点为 1024 的响应式应用程序。 当用户登录/注册时,将有几个问题需要回答。 在移动设备上,这将呈现为关于...的一个问题
我想知道如何调整InputContainer中的填充,并剪切下划线和文本之间的空间。 准确地说,我想在
我的网站上有一条带有链接的console.log消息。 样式有效,但链接仍为白色背景上的黑色字体。 我可以改变吗? $(函数() { var t = navigator.userAgent.
我有一个带有 windowsflag Qt::Popup 设置的小部件,我正在尝试创建平滑的圆角。 我尝试使用样式表,但角的透明部分变成黑色。一样的
react-native-mapbox-gl / 地图如何更改样式?
我在文档中看到了分层。 https://github.com/react-native-mapbox-gl/maps#layers 但我不明白如何改变建筑物和道路的颜色。以及如何更改标签中的文本。还有
我目前正在学习 WPF 动画。 目前我有这个按钮样式: <Setter Property="FontFamily" Value="{DynamicResource </desc> <question vote="0"> <p>我目前正在学习 WPF 动画。</p> <p>目前我有这个按钮样式:</p> <pre><code><Style TargetType="Button"> <Setter Property="FontFamily" Value="{DynamicResource DefaultFont}" /> <Setter Property="MinHeight" Value="{DynamicResource MinHeight}" /> <Setter Property="Background" Value="{DynamicResource C4}" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid SnapsToDevicePixels="True"> <Border x:Name="Border" BorderThickness="0" CornerRadius="{DynamicResource Radius}" BorderBrush="{TemplateBinding BorderBrush}"> <Border.Background> <SolidColorBrush x:Name="borderBackground" Color="{StaticResource Col5}" /> </Border.Background> <ContentPresenter x:Name="Content" VerticalAlignment="Center" HorizontalAlignment="Center" RecognizesAccessKey="True" /> </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" TargetName="Border" Value="Black" /> <Trigger.EnterActions> <BeginStoryboard x:Name="beginStoryboard"> <Storyboard> <ColorAnimation Storyboard.TargetName="borderBackground" Storyboard.TargetProperty="Color" To="{StaticResource Col2}" Duration="0:0:0.2"> </ColorAnimation> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <RemoveStoryboard BeginStoryboardName="beginStoryboard" /> <BeginStoryboard x:Name="e"> <Storyboard> <ColorAnimation Storyboard.TargetName="borderBackground" Storyboard.TargetProperty="Color" To="{StaticResource Col5}" Duration="0:0:0.2"> </ColorAnimation> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Style.Resources> <Style TargetType="Border"> <Setter Property="CornerRadius" Value="{DynamicResource Radius}" /> </Style> </Style.Resources> </Style> </code></pre> <p>如您所见,这种风格应该做一些事情:</p> <ul> <li>应用默认值 <pre><code>FontFamily</code></pre>、<pre><code>MinHeight</code></pre> 和 <pre><code>Background</code></pre>;</li> <li>使用 <pre><code>ColorAnimation</code></pre> 动画鼠标进入和鼠标离开效果。颜色被定义为具有 Col1、Col2 等名称的资源。</li> </ul> <p>一切正常(即使我怀疑这种风格可以用更简洁的方式重写,但我需要指出正确的方向)。</p> <p>我的问题是:我需要基于这个主样式创建另一个样式,所以我写了类似的内容:</p> <pre><code><Style TargetType="Button" x:Key="AccentOnMouseOver" BasedOn="{StaticResource {x:Type Button}}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" Value="DarkGreen"/> <Setter Property="BorderThickness" Value="1" /> </Trigger> </Style.Triggers> </Style> </code></pre> <p>不幸的是,这不起作用(应用了基本样式,但没有 <pre><code>BorderBrush</code></pre> 颜色)。 如何使用背景<pre><code>ColorAnimation</code></pre>编写基本样式,然后使用另一种样式派生,添加其他<pre><code>Triggers</code></pre>?</p> <p>解决方案是复制并粘贴整个基本样式,添加 x:Key 并编辑我需要的属性,但我想要更干净的东西(这样,如果我更改动画部分,它将应用于所有派生样式) .</p> <p>非常感谢任何帮助。</p> </question> <answer tick="false" vote="0"> <p>主要错误是对元素模板的逻辑及其与样式的交互的错误理解。</p> <ol> <li><p>在您的示例中,主边框显示边框,但它有一个“硬”指定值:<pre><code><Border x:Name="Border" BorderThickness="0"</code></pre>。至少,您需要将其更改为 <pre><code><Border x:Name="Border" BorderThickness="{TemplateBinding BorderThickness}"</code></pre>。</p> </li> <li><p>“MouseOver”状态的边框颜色在模板触发器中设置:</p> </li> </ol> <pre><code> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" TargetName="Border" Value="Black" /> </code></pre> <p>因此,在这种状态下,对父元素属性的绑定将不再起作用(其优先级低于模板触发setter):<pre><code><Border x:Name="Border" ... BorderBrush="{TemplateBinding BorderBrush}"></code></pre>。因此,对于这种状态,为父元素的属性设置值是没有意义的。</p> <p>您不能同时为一个属性设置多个值。因此,如果您稍后需要在使用元素的位置触发同一属性的更改,您应该想出某种机制来禁用模板中的触发器。</p> </answer> </body></html>
如何根据不同数据帧中的列的值突出显示一个数据帧中的行或字符串?
我希望能够从数据帧的一列中获取值,并在另一个数据帧中找到完全相同的值,以突出显示整行或仅突出显示字符串(无论哪种更容易/可能)。 数据...
当视口大于992px时,我想在以下两个实例中的菜单元素下显示一条灰线: 当页面被主动访问时,我希望线路保持在 pl...
使用 maatwebsite/excel 版本 3.1 直接从 laravel excel 中的数据库导出数据时,工作表样式不起作用
我尝试了很多方法来设计我的标题,但没有任何效果。我尝试了文档中给出的每种方法,也尝试了来自多个站点的多种方法,但样式现在在 Excel 工作表中可见。 使用这个包:&q...