none
斑竹再麻烦给个PasswordBox的template式样吧,我拿到的好像都不管用... RRS feed

  • 问题

  •      <Style TargetType="PasswordBox">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Control" xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
                            <aero:ListBoxChrome Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Name="Bd" RenderFocused="{TemplateBinding UIElement.IsKeyboardFocusWithin}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" SnapsToDevicePixels="True">
                                <ScrollViewer Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                            </aero:ListBoxChrome>
                            <ControlTemplate.Triggers>
                                <Trigger Property="UIElement.IsEnabled" Value="False">
                                    <Setter Property="aero:ListBoxChrome.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                                    <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="FontSize" Value="20"></Setter>
                <Setter Property="Padding" Value="1,5,0,0"></Setter>
               
                <Style.Triggers>
                    <Trigger Property="IsFocused" Value="True">
                        <Setter Property="Background" >
                            <Setter.Value>
                                <ImageBrush ImageSource="Resources/Login/输入框_选择.png">
                                </ImageBrush>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>

     

    这样图片还是没用郁闷,多谢斑竹拉

    2011年10月20日 8:52

答案

  • 好吧!

        <ControlTemplate TargetType="PasswordBox">
          <my:ListBoxChrome Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Name="Bd" RenderFocused="{TemplateBinding UIElement.IsKeyboardFocusWithin}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" SnapsToDevicePixels="True">
            <ScrollViewer Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
          </my:ListBoxChrome>
          <ControlTemplate.Triggers>
            <Trigger Property="UIElement.IsEnabled" Value="False">
              <Setter Property="my:ListBoxChrome.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
              <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
    

    你试试在ControlTemplate。Trigger里面把 ListBoxChrome.Background 改成:

    <Setter Property="my:ListBoxChrome.Background" TargetName="Bd" Value="{TemplateBinding Background}" />
    

    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • 已标记为答案 a013strife 2011年10月25日 4:34
    2011年10月20日 9:17
    版主
  • 因为你用的是VS 2008,所以我还是建议你把 TargetType 写全:  TargetType="{x:Type PasswordBox}"

    不过我测试了你的代码,在08 10下都没有问题,是不是你缺了什么程序集引用。


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • 已标记为答案 a013strife 2011年10月25日 4:34
    2011年10月25日 3:35
    版主

全部回复

  • 好吧!

        <ControlTemplate TargetType="PasswordBox">
          <my:ListBoxChrome Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Name="Bd" RenderFocused="{TemplateBinding UIElement.IsKeyboardFocusWithin}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" SnapsToDevicePixels="True">
            <ScrollViewer Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
          </my:ListBoxChrome>
          <ControlTemplate.Triggers>
            <Trigger Property="UIElement.IsEnabled" Value="False">
              <Setter Property="my:ListBoxChrome.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
              <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
    

    你试试在ControlTemplate。Trigger里面把 ListBoxChrome.Background 改成:

    <Setter Property="my:ListBoxChrome.Background" TargetName="Bd" Value="{TemplateBinding Background}" />
    

    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • 已标记为答案 a013strife 2011年10月25日 4:34
    2011年10月20日 9:17
    版主
  •  <Style TargetType="PasswordBox" >
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="PasswordBox" >
                            <aero:ListBoxChrome Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Name="Bd" RenderFocused="{TemplateBinding UIElement.IsKeyboardFocusWithin}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" SnapsToDevicePixels="True">
                                <ScrollViewer Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                            </aero:ListBoxChrome>
                            <ControlTemplate.Triggers>
                                <Trigger Property="UIElement.IsEnabled" Value="False">
                                    <Setter Property="aero:ListBoxChrome.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                                    <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

    这样写style貌似不行...不能写style的target=passwordbox?,谢谢!!!

    2011年10月25日 2:25
  • 因为你用的是VS 2008,所以我还是建议你把 TargetType 写全:  TargetType="{x:Type PasswordBox}"

    不过我测试了你的代码,在08 10下都没有问题,是不是你缺了什么程序集引用。


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • 已标记为答案 a013strife 2011年10月25日 4:34
    2011年10月25日 3:35
    版主
  • 应该行,我再调调
    2011年10月25日 4:34