标签: styling

在WPF中,如何防止我的样式被覆盖?

请不要陷入我的榜样,只是为了这个问题而忍受我:

在我的WPF应用程序中,如果我希望所有TextBox都具有"绿色"背景,我可以在我的Application.Resources中轻松设置它.

<Style TargetType="TextBox">
 <Setter Property="Background" Value="Green" />
</Style>
Run Code Online (Sandbox Code Playgroud)

完美地工作 ......(谢谢你WPF).但是,如果我在我的应用程序中的某个地方有一个TextBox,我想要添加更多样式 ......我失去了我的绿色背景.

例:

<TextBox>
 <TextBox.Style>
  <Style>
   <Style.Triggers>
    <Trigger Property="TextBox.IsMouseOver" Value="True">
     <Setter Property="TextBox.Foreground" Value="Red" />
    </Trigger>
  </Style.Triggers>
  </Style>
 </TextBox.Style>
</TextBox>
Run Code Online (Sandbox Code Playgroud)

当鼠标结束时,TextBox将正确地具有红色前景,但绿色背景完全丢失.

所以,问题是:我如何告诉WPF不要完全消除所有来自上面的样式,因为我有一个简单的,非冲突的,这么小的风格添加到控件的某个地方?

wpf styling

8
推荐指数
1
解决办法
4144
查看次数

WPF子菜单样式

我有一个ContextMenu样式和一个MenuItem样式,它们都在顶层菜单上正常工作.问题是如果我在菜单项中添加子菜单,则子菜单没有正确设置样式.看起来你现在只能设置菜单项的样式,而不是实际的子菜单,所以你不能替换IsMouseOver样式(它只是默认为在Windows上启用的任何主题).

我搜索和搜索过,我能找到的最接近的是MSDN上的论坛帖子http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/69269d23-f97c-42e3-a9dd-0e7c0ba49bdd ?prof = required但它实际上也没有正确回答问题,因为他的例子我遇到了同样的问题.任何帮助,将不胜感激!提前致谢.

编辑:周杰伦,这就是我在做的事情.这是一些代码,在UserControl.Resources中作为我的对象的顶部.

    <Style TargetType="{x:Type MenuItem}">
        <Setter Property="Background" Value="#0f3c5a"></Setter>
        <Setter Property="Foreground" Value="White"></Setter>
        <Style.Triggers>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="Black"></Setter>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="LightGray"></Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
    <Style TargetType="{x:Type ContextMenu}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <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 BorderThickness="0" x:Name="Border"  >
                     <StackPanel ClipToBounds="True" Orientation="Vertical"
                     IsItemsHost="True"/>
                     </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="Border" Property="Background" Value="#5082a4" /> …
Run Code Online (Sandbox Code Playgroud)

wpf contextmenu styling menuitem

8
推荐指数
1
解决办法
2万
查看次数

显示时,边距,位置和填充不起作用:设置了内联.相对位置也有奇怪的行为

我有两个CSS类:

.class1 {
    height: 100%;
    width: 300px;
    border: 1px none #B0B0B0;
    position: relative;
    display: inline;
    left: 10px;
}
.class2 {
    height: 100%;
    width: 200px;
    position: relative;
    display: inline;
    margin-left: 15px;
    background-color: #00CCCC;
    border-top-width: 1px;
    border-right-width: 1px;
    border-bottom-width: 1px;
    border-left-width: 1px;
    border-top-style: solid;
    border-right-style: solid;
    border-bottom-style: solid;
    border-left-style: solid;
}
Run Code Online (Sandbox Code Playgroud)

现在,正如您所看到的,它们都设置为一行显示(元素之间没有换行).哪个工作正常.但出于某种原因,自从我将显示设置为内联后,Padding,Positioning和Margin CSS都停止了工作.我可以添加一个保证金左10英寸,什么都不会发生.与填充和定位相同.

有谁能解释如何解决这个问题?

此外,我在两个类上都设置了相对位置,但是当在浏览器中查看页面时,在它应该只是之后的.class2圈数..class1.class1

有任何想法吗?

编辑:

好吧,所以我做了一个JSFiddle,但它似乎在那里播放更多....

看起来Width不行......

这里是:

http://jsfiddle.net/zYbwh/1/

css styling

8
推荐指数
1
解决办法
1万
查看次数

更改SystemTray进度指示器颜色

我需要改变颜色的SystemTray.ProgressIndicator颜色,我该怎么办?

我试着设置ForegroundColorSystemTray,它适用于纯文本不Inicator.指示灯始终使用PhoneAccent颜色.

styling progress-indicator windows-phone-7

8
推荐指数
1
解决办法
2406
查看次数

VisualStateManager - 显示控件聚焦时的鼠标悬停状态

我正在使用Windows 8样式(以前称为metro)创建WPF按钮.

我希望按钮的聚焦状态以稳固的背景显示.当鼠标悬停在控件上时,我希望背景稍微变暗以创建可以单击按钮的视觉提示.

不幸的是,我在下面写的XAML不起作用.聚焦状态显示正确,但当鼠标在控件上时,背景不会像我希望的那样变暗.

<Color x:Key="DoxCycleGreen">
    #FF8DC63F
</Color>

<!-- Soft Interface : DoxCycle Green --> 
<Color x:Key="DoxCycleGreenSoft">
    #FFC0DC8F
</Color>

<Style x:Key="MetroButton" TargetType="{x:Type Button}">
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border Name="RootElement">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup Name="CommonStates">
                            <VisualState Name="Normal" />
                            <VisualState Name="MouseOver">
                                <Storyboard>
                                    <ColorAnimation Storyboard.TargetName="BackgroundColor" Storyboard.TargetProperty="Color" To="{StaticResource DoxCycleGreen}" Duration="0:0:0.150" />
                                    <ColorAnimation Storyboard.TargetName="FontColor" Storyboard.TargetProperty="Color" To="White" Duration="0:0:0.150" />
                                </Storyboard>
                            </VisualState>
                            <VisualState Name="Focused">
                                <Storyboard>
                                    <ColorAnimation Storyboard.TargetName="BackgroundColor" Storyboard.TargetProperty="Color" To="{StaticResource DoxCycleGreenSoft}" Duration="0:0:0.150" />
                                    <ColorAnimation Storyboard.TargetName="FontColor" Storyboard.TargetProperty="Color" To="White" Duration="0:0:0.150" />
                                </Storyboard>
                            </VisualState>
                            <VisualState Name="Pressed">
                                <Storyboard>
                                    <ColorAnimation Storyboard.TargetName="BackgroundColor" …
Run Code Online (Sandbox Code Playgroud)

wpf styling visualstatemanager controltemplate

8
推荐指数
1
解决办法
2万
查看次数

Graphml javascript库在网页中绘制

我有一个GraphML文件,我必须在网页上显示它,以及使用JavaScript更改显示属性(比如更改节点的颜色,边缘等).

可能吗?

如果有任何JavaScript库要加载,解析并在网页上绘制GraphML,请告诉我.

javascript visualization styling graphml

8
推荐指数
2
解决办法
5539
查看次数

使用续行分配 - Python

我希望我没有违反任何SO规则:当变量嵌套多个级别深度,具有相当长的名称并且被赋予相当长的值/表达式时,为变量赋值的首选样式是什么.

例如:

if this:
    if that:
        if here:
            if there:
                 big_variable['big_key']['big_value'] = another_big_variable_that_pushes_line_over_79_characters
                 other_thing = something
Run Code Online (Sandbox Code Playgroud)

字符限制违规只是单个数字,但我想清理我的代码,以便尽可能忠实地遵循PEP 8.我已经完成了以下操作,但我仍然是python的新手,我不确定是否会让经验丰富的python程序员感到畏缩:

if this:
    if that:
        if here:
            if there:
                big_variable['big_key']['big_value'] = \
                    another_big_variable_that_pushes_line_over_79_characters
                other_thing = something
Run Code Online (Sandbox Code Playgroud)

我觉得线条延续字符有些禁忌; 但是,如果我正在使用这些大字典而且我不能在变量名称的中间做一个干净的休息,我真的不能想到一个更清洁的解决方案.谢谢您的帮助!

python styling pep

8
推荐指数
2
解决办法
1万
查看次数

显示背景颜色的百分比栏

例如,如果我有一个包含两列和两行的表:

Col1       Percentage
50            50% 
70            70%
Run Code Online (Sandbox Code Playgroud)

如何填充百分比列,颜色代表COl1的值?像这样的东西:

在此输入图像描述

html css styling

8
推荐指数
1
解决办法
5697
查看次数

你可以在'label'标签中添加一个类吗?

这可能是一个愚蠢的问题,但我只是想知道是否可以在'label'标签中添加一个类而不必将其包装在'span'标签中来设置它.我正在阅读"CSS:The Missing Manual",它告诉我,为了设计一堆标签标签,我应该用'span'标签包装每个我想要样式的标签.

<label class="name">Name:</label>
Run Code Online (Sandbox Code Playgroud)

css forms label class styling

8
推荐指数
1
解决办法
1万
查看次数

在 MUI v5 中,如何在开发工具 DOM 中调试/查找特定元素/样式/类?

在 MUI v4 中,检查 DOM 并隔离该文件中的确切组件文件和样式块非常容易:

MUI v4 查找特定元素/样式类的方法

然而,在 MUI v5 中,这是不可能的,这使得调试和查找隐藏在代码中的样式元素变得更加困难(我的屏幕截图很简单,但想象一下有一个包含数百个组件的大型应用程序):

MUI v5 通过 DOM 检查进行样式设置的方法

是否有更好的调试 MUI v5 可以更快地查找/隔离代码中的特定组件/样式块?

另外,以下是我发现的在 MUI v5 中进行(和不进行)样式设置的各种方法,但是,在检查 DOM 时,它们都没有显示出良好的调试信息(有关 、classesstyles之间的区别,请参阅 github 源代码sty):

      {/* OK - these work */}
      <Box sx={{ ...classes.text }}>HELLO</Box>
      <Box style={classes.text}>HELLO</Box>
      <Box css={styles.text}>HELLO</Box>
      <Box sx={sty.text}>HELLO</Box>

      {/* FAIL - these do not work - the v4 way, for completeness */}
      <Box classes={{ root: classes.text }}>HELLO</Box>
      <Box className={classes.text}>HELLO</Box>
      <Box class={classes.text}>HELLO</Box>
Run Code Online (Sandbox Code Playgroud)

来源: https: //github.com/masaok/react-css-google-demo/blob/master/src/archive/GoogleTest.jsx#L72-L81

css styling reactjs material-ui

8
推荐指数
1
解决办法
2075
查看次数