1

我想在我的 WPF UniformGrid 中的元素周围添加一个边框。我试过的:

<Window.Resources>
    <DataTemplate x:Key="GridCell">
        <Border BorderBrush="DarkGray" BorderThickness="5"></Border>
    </DataTemplate>
</Window.Resources>

...和...

<UniformGrid Name="grid">
    <ItemsControl ItemTemplate="{StaticResource GridCell}"></ItemsControl>
</UniformGrid>

它不起作用(不出现边框)。我想让 UniformGrid 的每个子项(以编程方式创建的按钮,因此它们不会出现在这里)都有一个边框。它需要看起来像一个网格……用水平和垂直网格线划分行和列。

4

1 回答 1

3
<Grid>
        <ItemsControl ItemsSource="{Binding NumericalPatches}" >
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <UniformGrid Rows="7" Columns="7"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="DimGray" BorderThickness="3">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <TextBlock Grid.Row="0" Grid.Column="0" Margin="5" Text="{Binding StringFormat=F4,Path=Red}" FontSize="14" Foreground="Red"/>
                            <TextBlock Grid.Row="0" Grid.Column="1" Margin="5" Text="{Binding StringFormat=F4,Path=Green}" FontSize="14" Foreground="Green"/>
                            <TextBlock Grid.Row="1" Grid.Column="0" Margin="5" Text="{Binding StringFormat=F4,Path=Blue}" FontSize="14" Foreground="Blue"/>
                            <TextBlock Grid.Row="1" Grid.Column="1" Margin="5" Text="{Binding StringFormat=F4,Path=Chroma}" FontSize="14" Foreground="White"/>

                        </Grid>
                    </Border>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
于 2015-01-12T14:58:46.980 回答