在WPF RichTextBox代码隐藏中显示/隐藏左右边框?

时间:2016-02-03 12:04:31

标签: c# wpf border richtextbox

我想隐藏/显示WPF <!DOCTYPE html><html><head><title>Foodle Bardle</title><link rel="stylesheet" href="/stylesheets/bootstrap.css"><link rel="stylesheet" href="/stylesheets/bootstrap-theme.css"><link rel="stylesheet" href="/stylesheets/style.css"><script type="text/javascript" src="/javascripts/jquery.min.js"></script><script type="text/javascript" src="/javascripts/bootstrap.min.js"></script></head><body><nav class="navbar navbar-inverse navbar-fixed-bar" aria-expanded="false" aria-controls="navbar" data-toggle="collapse" class="navbar-toggle collapsed"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a href="#" class="navbar-brand">Foodle Bardle</a></div><div id="navbar" aria-expanded="true" class="navbar-collapse collapse in"><form class="navbar-form navbar-right"><div class="form-group"><input type="text" placeholder="email" class="form-control"></div><div class="form-group"><input type="password" placeholder="password" class="form-control"></div><button type="success" class="btn btn-success">Sign In</button></form></div></div></nav><div class="jumbotron"><div class="container"><h1>Sample</h1><p>Welcome to Sample. Lots of sites and apps offer a foo. Some even add a bit of the bar (foobar fooy and doey) way to bar up. Here is a place to nuture your bardle using all the tools available. </p></div></div><div class="container"><div class="row"><div class="col-md-4"><h2>Foo Integration</h2><p>Foo work is demanding, and solving complex bars all day will actually make productivity smurf, but there are ways to maximize hoey bar over time. </p><a class="btn btn-primary btn-lg">Learn More</a></div><div class="col-md-4"><h2>GTD - Getting Bardle Done</h2><p>David Barish gave us some insights that can help us keep our foodle focused on what matters at the moment. </p><a class="btn btn-primary btn-lg">Learn More</a></div><div class="col-md-4"><h2>SRS - Spaced foobardle Software</h2><p>One of psychology's best kept secrets, SFS is a way to overcome much of the innefiency in learning. All people forget and learn in some predictable ways, SFS puts the computer to task, scheduling well structed foodle bars or bardle foos for review at the ideal moment. </p><a class="btn btn-primary btn-lg">Learn More </a></div></div></div></body></html> 左侧边框有时会出现在代码后面,有时也会出现右侧边框。

这可以实现吗?

我已经尝试过XAML,就像Private Sub Copy_Images() Dim wks as worksheet, wks2 As Worksheet Set wks = Sheets("export") Set wks2 = Sheets("HomePage") wks2.Shapes("picture").Copy wks.range("A1").Paste End Sub 一样。它隐藏了我的右侧,现在我需要显示右侧边框并隐藏我的右侧边框。

我该怎么做?

已更新:

RichTextBox

以上是我的XAML。

borderthickness ="3,3,0,3"

但它不起作用。

此致 阿琼

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码执行相同的操作:

myRichTextBox.BorderThickness = new Thickness(3);

然后,如果所有边框都需要具有相同的厚度,则只能使用一个数字:

<Style x:Key="MyStyleNoBorders" BasedOn="{x:Null}" TargetType="{x:Type RichTextBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type RichTextBox}">
                <Border x:Name="bg" BorderBrush="Yellow" BorderThickness="0,3,0,3" Background="{TemplateBinding Background}">
                    <ScrollViewer x:Name="PART_ContentHost"  IsDeferredScrollingEnabled="True" CanContentScroll="False" />
                </Border>                       
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style x:Key="MyStyleBothBorders" BasedOn="{x:Null}" TargetType="{x:Type RichTextBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type RichTextBox}">
                <Border x:Name="bg" BorderBrush="Yellow" BorderThickness="3" Background="{TemplateBinding Background}">
                    <ScrollViewer x:Name="PART_ContentHost"  IsDeferredScrollingEnabled="True" CanContentScroll="False" />
                </Border>                       
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

修改

由于您正在使用样式,您可以定义多个样式,然后在它们之间切换:

RichTextBox

确保txtAppendValue.Style = FindResource("MyStyleNoBorders") as Style; 不是太宽,不适合屏幕,否则您将无法看到边框。然后在代码中使用一个调用来改变样式:

txtAppendValue.Style = FindResource("MyStyleBothBorders") as Style;

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation