設置了scrollview . verticalscrollbarvisibility = "自動"后,文本框ScrollBar不會出現

[英]Textbox ScrollBar is not coming after setting ScrollViewer.VerticalScrollBarVisibility=“Auto”


I have silverlight web app.I am showing log information in child windows.child window contain a textbox control.I have set ScrollViewer.VerticalScrollBarVisibility="Auto" but vertical scroll bar is not showing up.please help me on this.

我有silverlight web應用,我在子窗口中顯示日志信息。子窗口包含一個文本框控件。我有設置滾動視圖。垂直滾動條="自動",但垂直滾動條沒有顯示。請在這方面幫助我。

XAML

XAML

<controls:ChildWindow x:Class="LogPopUpWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
       Width="600" Height="400" 
       Title="" HasCloseButton="False">
<Grid x:Name="LayoutRoot" Margin="2">
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <TextBox x:Name="LogEvents" IsReadOnly="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
     ScrollViewer.VerticalScrollBarVisibility="Visible"></TextBox>
    <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
</Grid>

C#

c#

 public void RefreshLogs(string message = "")
    {
        StringBuilder text = new StringBuilder();
        if (string.IsNullOrEmpty(message))
        {
            if (Logger.GetLogs() != null)
            {
                Logger.GetLogs().ForEach(b =>
                {
                    text.AppendFormat("{2}{0}:  {1}{2}", b.UserTargetOperation, b.UserEventDate.ToString(), Environment.NewLine);
                    foreach (KeyValuePair<string, string> pair in b.Parameters)
                    {
                        text.AppendFormat("         {0} : {1}{2}", pair.Key, pair.Value, Environment.NewLine);
                    }
                });
            }

            LogEvents.Text = text.ToString();
        }
        else
        {
            LogEvents.Text = message;
            LogEvents.TextWrapping = TextWrapping.Wrap;
        }
    }

Button Handler Coder

按鈕的處理程序編碼

private void ShowLogLink_Click(object sender, System.Windows.RoutedEventArgs e)
    {

        ///Logger.GetLogs();
        ///
        LogPopUpWindow win = new LogPopUpWindow();
        win.RefreshLogs();
        win.Show();
    }

2 个解决方案

#1


0  

I would put this just in a comment but I don't have enough rep. I tried to reproduce the error you are describing of that the Vertical Scroll bar is not displaying, but when I fill the textbox with more text than it's height holds, the scroll bar shows.

我把它寫在評論里,但是我沒有足夠的代表我試圖重現你描述的錯誤垂直滾動條沒有顯示,但是當我用比它的高度更多的文本填充文本框時,滾動條會顯示出來。

Is there any other portions influencing your problem that you did not list?

有沒有其他的部分影響你的問題,你沒有列出?

#2


0  

Issue is resolved.I added vertical scroll properties in the code and it is working.

問題是解決了。我在代碼中添加了垂直滾動屬性,它正在工作。

public void RefreshLogs(string message = "")
    {
        StringBuilder text = new StringBuilder();
        if (string.IsNullOrEmpty(message))
        {
            if (Logger.GetLogs() != null)
            {
                Logger.GetLogs().ForEach(b =>
                {
                    text.AppendFormat("{2}{0}:  {1}{2}", b.UserTargetOperation, b.UserEventDate.ToString(), Environment.NewLine);
                    foreach (KeyValuePair<string, string> pair in b.Parameters)
                    {
                        text.AppendFormat("         {0} : {1}{2}", pair.Key, pair.Value, Environment.NewLine);
                    }
                });
            }

            LogEvents.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; // added
            LogEvents.Text = text.ToString();
        }
        else
        {
            **LogEvents.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;** // added
            LogEvents.Text = message;
            LogEvents.TextWrapping = TextWrapping.Wrap;
        }
    }
}

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/08/01/83d3c3d626ea24aae94abd8b109baa9d.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com