2013-08-01 55 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; 
     } 
    } 
}