首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TextBox ControlTemplate上的自动滚动

问TextBox ControlTemplate上的自动滚动
EN

Stack Overflow用户
提问于 2018-08-26 01:52:13
回答 1查看 71关注 0票数 0

我正在使用下面的TextBox,为了在文本上应用DropShadowEffect,它使用了ControlTemplate。我设法让TextWrapping正常工作,但是一旦TextBox填满,它的内容就看不见了。如何将自动滚动复制到本机TextBox的底部功能?

代码语言:javascript
复制
<TextBox TextWrapping="Wrap"
           Foreground="LimeGreen"
           Background="Black"
           Margin="10,40,10,40"
           FontSize="40"
           HorizontalAlignment="Stretch"
           x:Name="Inp"
           FontFamily="Courier New"
           CaretBrush='LimeGreen'>
    <TextBox.Resources>
      <Style TargetType="{x:Type TextBox}">
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="TextBox">
              <Grid x:Name="RootElement">
                <ScrollViewer>
                <ContentPresenter Content="{TemplateBinding Text}">
                  <ContentPresenter.Effect>
                    <DropShadowEffect ShadowDepth="4"
                                      Direction="330"
                                      Color="LimeGreen"
                                      Opacity="1"
                                      BlurRadius="5" />
                  </ContentPresenter.Effect>
                  <ContentPresenter.Resources>
                    <Style TargetType="{x:Type TextBlock}">
                      <Setter Property='TextWrapping'
                              Value='Wrap' />
                    </Style>
                  </ContentPresenter.Resources>
                </ContentPresenter>
                </ScrollViewer>
              </Grid>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
    </TextBox.Resources>
  </TextBox>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-26 02:19:45

此解决方案与您可能预期的略有不同。我认为使用ContentPresenter是错误的,因为最终您仍然想要TextBox的功能。所以我的解决方案专注于去除会弄乱投影效果的边框和焦点指示器:

代码语言:javascript
复制
<TextBox x:Name="Inp"
            Height="100"
            HorizontalAlignment="Stretch"
            Background="Transparent"
            BorderBrush="Transparent"
            BorderThickness="0"
            CaretBrush="LimeGreen"
            FontFamily="Courier New"
            FontSize="40"
            Foreground="LimeGreen"
            TextWrapping="Wrap">
    <TextBox.Effect>
        <DropShadowEffect BlurRadius="5"
                            Direction="330"
                            Opacity="1"
                            ShadowDepth="4"
                            Color="LimeGreen" />
    </TextBox.Effect>
    <TextBox.FocusVisualStyle>
        <Style>
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate/>
                </Setter.Value>
            </Setter>
        </Style>
    </TextBox.FocusVisualStyle>
</TextBox>

我设置背景,阴影为透明(=>无阴影)。我去掉了ContentPresenter;它现在是一个普通的文本框了。为了去掉焦点边框,我把FocusVisualStyle设置为空模板。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52019825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档