2016-07-23 10 views
1

を水平線を追加TextBlock.Inlines - 私は水平線で割ったログエントリを追加してい以下

Dim vLogText = vLog.Split("^") 
      Dim vRows As Integer = vLogText.Length - 1 
      For i As Integer = 0 To vRows 
       Dim Subrow As String = vLogText(i) 
       LogTB.Inlines.Add(Subrow) 
       LogTB.Inlines.Add(New Line With {.X1 = 0, .Y1 = 0, .X2 = 300, .Y2 = 0, .Stroke = New SolidColorBrush(Colors.Gray), .StrokeThickness = 4.0}) 
      Next 

これは私がプリセット長さ(上記の例では300と言う)をしたい場合はOKです - しかし、それは必要がある場合それがどのように達成されるのか、コンテナの幅全体に伸びるのですか?ここでAnjum

によって供給答える返信に

おかげ

追加はメイングリッドの一部であるグリッドを追加する方法...

#Region "Right Grid" 

Private Function RightGrid() As Grid 
    Try 
     Dim MainGrid As New Grid 
     Dim vGrid As New Grid 
     Dim SV As New ScrollViewer 
     With SV 
      .Name = "RightGrid_SV" 
      .Content = vGrid 
      .VerticalScrollBarVisibility = ScrollBarVisibility.Auto 
     End With 
     RegisterControl(WorkOrder_Grid, SV) 
     MainGrid.Children.Add(SV) 


     'Add in the status and log 

     Dim LogLB As New Label 
     With LogLB 
      .Name = "WorkOrder_LogLB" 
     End With 
     RegisterControl(WorkOrder_Grid, LogLB) 
     vGrid.Children.Add(LogLB) 

     If IsNewRecord = True Then 
      'Add some help data 
      Dim SP As New StackPanel 


      Dim HeaderTB As New TextBlock 
      With HeaderTB 
       .Text = "ADDING A NEW WORK ORDER" & Environment.NewLine 
       .HorizontalAlignment = HorizontalAlignment.Center 
       .FontWeight = FontWeights.Bold 
      End With 

      Dim DatesHeaderTB As New TextBlock 
      With DatesHeaderTB 
       .Text = "Dates" 
       .TextDecorations = TextDecorations.Underline 
      End With 

      Dim DatesContentTB As New TextBlock 
      With DatesContentTB 
       .Text = "Enter the Work Order date and the date the Work needs to be completed by." & Environment.NewLine 
       .TextWrapping = TextWrapping.Wrap 
      End With 

      Dim UnitHeaderTB As New TextBlock 
      With UnitHeaderTB 
       .Text = "Unit/Common Area" 
       .TextDecorations = TextDecorations.Underline 
      End With 

      Dim vUnit As String = "If the Work Order relates to a homeowners property, insert the details using the button. " 
      vUnit += "If the homeowners have a registered account they will be updated by email each time the Work Order status is changed!" & Environment.NewLine & Environment.NewLine 
      vUnit += "If the Work Order relates to a common area (e.g. Recreation grounds, Clubhouse...) just enter a short description of that area." & Environment.NewLine 
      Dim UnitContentTB As New TextBlock 
      With UnitContentTB 
       .Text = vUnit 
       .TextWrapping = TextWrapping.Wrap 
      End With 

      Dim TypeHeaderTB As New TextBlock 
      With TypeHeaderTB 
       .Text = "Work Type" 
       .TextDecorations = TextDecorations.Underline 
      End With 

      Dim TypeContentTB As New TextBlock 
      With TypeContentTB 
       .Text = "A short description of the type of work (e.g. Spinklers, Lights not working...)" & Environment.NewLine 
       .TextWrapping = TextWrapping.Wrap 
      End With 

      Dim DetailsHeaderTB As New TextBlock 
      With DetailsHeaderTB 
       .Text = "Details/Instructions" 
       .TextDecorations = TextDecorations.Underline 
      End With 

      Dim DetailsContentTB As New TextBlock 
      With DetailsContentTB 
       .Text = "Add any more details or instructions to help the supplier." & Environment.NewLine 
       .TextWrapping = TextWrapping.Wrap 
      End With 

      Dim SupplierHeaderTB As New TextBlock 
      With SupplierHeaderTB 
       .Text = "Supplier" 
       .TextDecorations = TextDecorations.Underline 
      End With 

      Dim SupplierContentTB As New TextBlock 
      With SupplierContentTB 
       .Text = "Insert the supplier using the button." & Environment.NewLine & Environment.NewLine & "You can still save the Work Order without entering a supplier, but the Work Order document will not be generated!" & Environment.NewLine 
       .TextWrapping = TextWrapping.Wrap 
      End With 

      Dim EmailHeaderTB As New TextBlock 
      With EmailHeaderTB 
       .Text = "Supplier Email" 
       .TextDecorations = TextDecorations.Underline 
      End With 

      Dim EmailContentTB As New TextBlock 
      With EmailContentTB 
       .Text = "The default email address will be loaded when you insert the supplier (this can be overridden) " & Environment.NewLine & Environment.NewLine & "If the email address is blank, or not valid, the Work Order document will not be emailed, but generated as a PDF to print locally and mail!" & Environment.NewLine 
       .TextWrapping = TextWrapping.Wrap 
      End With 

      Dim ImageHeaderTB As New TextBlock 
      With ImageHeaderTB 
       .Text = "Upload Image" 
       .TextDecorations = TextDecorations.Underline 
      End With 

      Dim ImageContentTB As New TextBlock 
      With ImageContentTB 
       .Text = "If you have a photograph of the work required, browse to the image. It will be included in the Work Order document." & Environment.NewLine 
       .TextWrapping = TextWrapping.Wrap 
      End With 

      Dim CostHeaderTB As New TextBlock 
      With CostHeaderTB 
       .Text = "Estimated Cost" 
       .TextDecorations = TextDecorations.Underline 
      End With 

      Dim vCost As String = "If you enter an estimated cost the Work Order will be authorised up to that amount" & Environment.NewLine & Environment.NewLine 
      vCost += "If the supplier is unable to carry out the work for this amount or less (or the field is left at zero) the work will not be authorised and they must revert back to the sender with a quote!" & Environment.NewLine & Environment.NewLine 
      vCost += "When estimated costs are used a lot it is a good idea to check the supplier invoices do not regularly equal (or a dollar or two less) than the estimated amount!!" & Environment.NewLine 

      Dim CostContentTB As New TextBlock 
      With CostContentTB 
       .Text = vCost 
       .TextWrapping = TextWrapping.Wrap 
      End With 

      Dim SiteHeaderTB As New TextBlock 
      With SiteHeaderTB 
       .Text = "Smart Manager" 
       .TextDecorations = TextDecorations.Underline 
       .Foreground = New SolidColorBrush(Colors.Blue) 
      End With 

      Dim SiteContentTB As New TextBlock 
      With SiteContentTB 
       .Text = "You can also enter Work Orders, whilst on-site, with a Smart Phone or Tablet using Smart Manager!" & Environment.NewLine 
       .TextWrapping = TextWrapping.Wrap 
       .Foreground = New SolidColorBrush(Colors.Blue) 
      End With 

      With SP.Children 
       .Add(HeaderTB) 
       .Add(DatesHeaderTB) 
       .Add(DatesContentTB) 
       .Add(UnitHeaderTB) 
       .Add(UnitContentTB) 
       .Add(TypeHeaderTB) 
       .Add(TypeContentTB) 
       .Add(DetailsHeaderTB) 
       .Add(DetailsContentTB) 
       .Add(SupplierHeaderTB) 
       .Add(SupplierContentTB) 
       .Add(EmailHeaderTB) 
       .Add(EmailContentTB) 
       .Add(ImageHeaderTB) 
       .Add(ImageContentTB) 
       .Add(CostHeaderTB) 
       .Add(CostContentTB) 
       .Add(SiteHeaderTB) 
       .Add(SiteContentTB) 
      End With 

      LogLB.Content = SP 
     End If 

     Return MainGrid 
    Catch ex As Exception 
     EmailError(ex) 
     Return Nothing 
    End Try 
End Function 

..and ..です。

Private Function CentreGrid() As Grid 
    Try 
     Dim vGrid As New Grid 
     For i As Integer = 0 To 2 
      Dim vCol As New ColumnDefinition 
      If i = 1 Then 
       vCol.Width = New GridLength(5, GridUnitType.Auto) 
      End If 
      vGrid.ColumnDefinitions.Add(vCol) 
     Next 

     Dim vLeftGrid As Grid = LeftGrid() 
     Grid.SetColumn(vLeftGrid, 0) 
     vGrid.Children.Add(vLeftGrid) 

     Dim vGridSplitter As New GridSplitter 
     With vGridSplitter 
      .VerticalAlignment = Windows.VerticalAlignment.Stretch 
      .HorizontalAlignment = Windows.HorizontalAlignment.Center 
      .ResizeBehavior = GridResizeBehavior.PreviousAndNext 
      .Background = New SolidColorBrush(Colors.Blue) 
      .Width = 5 
      .Margin = New Thickness(5) 
     End With 
     Grid.SetColumn(vGridSplitter, 1) 
     vGrid.Children.Add(vGridSplitter) 

     Dim vRightGrid As Grid = RightGrid() 
     Grid.SetColumn(vRightGrid, 2) 
     vGrid.Children.Add(vRightGrid) 

     Return vGrid 
    Catch ex As Exception 
     EmailError(ex) 
     Return Nothing 
    End Try 
End Function 

ページを開いたとき、これは水平線のように見えます(青色のもの)。

Image one - opened

..and(ウィンドウを大きくすると、同じこと)これは、私はコードビハインド使用することはありません

Image two - size adjusted

答えて

2

ベストのようなものを試してみてください。感謝の返事を -

 Line line = new Line() { Stroke = Brushes.Blue}; 
     Binding binding = new Binding("ActualWidth"); 
     binding.RelativeSource = new RelativeSource() { Mode=RelativeSourceMode.FindAncestor, AncestorType=typeof(TextBlock) }; 
     BindingOperations.SetBinding(line, Line.X2Property, binding); 

     LogTB.Inlines.Add(line); 
+0

これは非常に近いです - ページがロードされると幅が設定されますが、TextBlockサイズが調整された場合(ウィンドウサイズが変わるとグリッドスプリッタが移動します)、同じ幅で固定されます。 – gchq

+0

@gchqいいえチェックしていませんそれ。 – AnjumSKhan

+0

Anjum - ありがとうございました!私は、前後に表示するいくつかのスクリーンショットと、それが貢献する要素かもしれないので、展開方法を示すためのいくつかの追加コードを追加しました。 – gchq

2

GridSplitterが左に移動したときに何が起こるかでありますこのようなもののために。絶対に痛い。 UI開発の大部分をXAMLフロントエンドに限定した場合は、WPFの方がはるかに扱いが簡単です。 X2プロパティのBindingを設定し、TextBlockActualWidthに設定することです。この

<Window x:Class="WpfApplication3.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:local="clr-namespace:WpfApplication3" 
     xmlns:sys="clr-namespace:System;assembly=mscorlib" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <Grid.Resources> 
      <DataTemplate x:Key="MyTemplate"> 
       <StackPanel Orientation="Vertical"> 
        <TextBlock Text="{Binding}" /> 
        <Line X1="0" X2="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" Stroke="Black" /> 
       </StackPanel> 
      </DataTemplate> 
     </Grid.Resources> 
     <ItemsControl ItemTemplate="{StaticResource MyTemplate}"> 
      <ItemsControl.Items> 
       <sys:String>One</sys:String> 
       <sys:String>Two</sys:String> 
       <sys:String>Three</sys:String> 
      </ItemsControl.Items> 
     </ItemsControl> 
    </Grid> 
</Window> 
+0

こんにちはジェイスを:以下

あなたはVB.netに変更することができ、C#のコードです。このプロジェクトは、XAMLを管理するには大きすぎる(1ページに20k行になる可能性がある)、多くのDBフィード動的設定があり、メインウィンドウのスケルトンとは別にすべてがコードで記述されている。後ろにコードを置くと変更を見つけやすくなります – gchq

+0

MVVMだけでなくMVVMでもクラッシュコースを取ることができます。誰かが「すべてがコードビハインドで書かれている」と言うのを聞くたびに、彼らは通常、難しいやり方をしてきました。 – Jace

+0

Jace - Aは、あなたの言うことを感謝し、おそらくもっと難しいです。質問の一部である例では、ユーザーの選択に従って異なるグリッドがページに読み込まれ、他の項目がバックエンドデータに基づいて動的にロードされています – gchq

関連する問題