web-dev-qa-db-ja.com

WPFのグリッドの一部のセルの境界線

データグリッドがあります。グリッド全体ではなく、一部のセルにいくつかの境界線を作成したいと思います。

例えば:

  1. 列2行2および3
  2. 列4行3および4。

XAMLコードを添付します。

よろしくお願いします。

<Grid Grid.Column="1">
<Grid.RowDefinitions>
    <RowDefinition Height="38"></RowDefinition>
    <RowDefinition Height="38*"></RowDefinition>
    <RowDefinition Height="38*"></RowDefinition>
    <RowDefinition Height="37*"></RowDefinition>
    <RowDefinition Height="38*"></RowDefinition>
    <RowDefinition Height="30"></RowDefinition>
    <RowDefinition Height="37*"></RowDefinition>
    <RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="0.5*"></ColumnDefinition>
    <ColumnDefinition Width="0.05*"></ColumnDefinition>
    <ColumnDefinition Width="0.5*"></ColumnDefinition>
    <ColumnDefinition Width="0.05*"></ColumnDefinition>
    <ColumnDefinition Width="0.5*"></ColumnDefinition>
    <ColumnDefinition Width="0.1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Content="Select relay:" HorizontalAlignment="Center" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"></Label>
<Label Content="Select State:" HorizontalAlignment="Center" Grid.Row="1" Grid.Column="2" VerticalAlignment="Bottom"></Label>

<ComboBox x:Name="CBRelayNumber" VerticalAlignment="Center" Grid.Row="0" Grid.Column="2">
    <ComboBoxItem Content="ALL Relay" HorizontalAlignment="Center" />
    <ComboBoxItem Content="Relay 1" Tag="0" HorizontalAlignment="Center" />
    <ComboBoxItem Content="Relay 2" Tag="1" 

</ComboBox>
<ComboBox x:Name="CBRelayState" VerticalAlignment="Center" Grid.Row="1" Grid.Column="2">
    <ComboBoxItem Content="ON" HorizontalAlignment="Center" />
    <ComboBoxItem Content="OFF" HorizontalAlignment="Center" />
</ComboBox>

<Label Content="Select Delay (msec):" HorizontalAlignment="Center" Grid.Row="0" Grid.Column="4" VerticalAlignment="Bottom" Grid.RowSpan="2"></Label>
<TextBox x:Name="tbAddTime" VerticalAlignment="Center" Grid.Column="4" Grid.Row="1"></TextBox>
<Button Content="Add" x:Name="AddDelay" Grid.Row="2" Grid.Column="4" VerticalAlignment="Center" Click="AddDelay_Click" ></Button>

<Button Content="Open Several Relays" x:Name="AddSeveralRelay" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Click="AddSeveralRelay_Click" ></Button>
<Button Content="Add" x:Name="AddRelay" Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" Click="AddRelay_Click" ></Button>

<Label Content="Times to perform:" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="0" Grid.Row="3"></Label>
<TextBox x:Name="tbLoop" Grid.Column="2" Grid.Row="3" VerticalAlignment="Center"></TextBox>
<Button Content="Save Scenario" x:Name="btnSave" Grid.Row="5" Grid.Column="0" Click="btnSave_Click"></Button>
<Button Content="Load Scenario" x:Name="btnLoad" Grid.Row="7" Grid.Column="0" Click="btnLoad_Click"/>
<Button Content="Start" x:Name="btnStart" Grid.Row="5" Grid.Column="4" Click="btnStart_Click"></Button>
<Button Content="Clear" x:Name="btnClear" Grid.Row="7" Grid.Column="4" Click="btnClear_Click"></Button>

<CheckBox x:Name="cbPostPreAllOFF" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="4" Grid.Column="2" Content="Pre-Post Relay OFF" IsChecked="True" Click="cbPostPreAllOFF_Checked"></CheckBox>

正しいGrid.Column、Grid.Row、およびGrid.RowSpan属性を使用してグリッド内にBorderを追加します。

<Grid Grid.Column="1">
    <!--row definitions, columns definitions, controls-->

    <Border BorderThickness="1" BorderBrush="Green" 
            Grid.Column="2" Grid.Row="2" Grid.RowSpan="2"/>
    <Border BorderThickness="1" BorderBrush="Green" 
            Grid.Column="4" Grid.Row="3" Grid.RowSpan="2"/>
</Grid>
10
ASh

これは、列0、行1から列+ 2、行+4に境界線を描画するためのトリックでした。

<Grid Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Grid.RowSpan="4">
  <Border BorderThickness="1" BorderBrush="Black" />           
</Grid>
0
dZZx