2013-08-01 28 views
0

后不来我的Silverlight网络app.I正在显示子windows.child窗口日志信息包含一个文本框control.I已设置ScrollViewer.VerticalScrollBarVisibility =“自动”,但垂直滚动条不显示up.please帮助我。文本框滚动条设置ScrollViewer.VerticalScrollBarVisibility =“自动”

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#

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; 
     } 
    } 

按钮处理程序编码器

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

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

我错过了什么?这是我所有的代码。 –

回答

0

我会把这只是一个评论,但我没有足够的代表。我试图重现你所描述的垂直滚动条不显示的错误,但是当我用比文本框高度更大的文本填充文本框时,会显示滚动条。

是否有其他部分影响您未列出的问题?

+0

除此之外,我有按钮处理程序代码,我启动子窗口。这是我有的所有代码。我尝试过不同的示例以及还有我没有得到TextBox滚动条。更新问题 –

+0

这是一个伸展,但也许尝试等待win.RefreshLog()。我并没有真正的方法来测试这个,但也许'胜利'是在文本填充和高度设置之前呈现的。 – QckLrner

0

问题已解决。我在代码中添加了垂直滚动属性,它正在工作。

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; 
     } 
    } 
}