在 ItemsControl WPF 上设置网格线样式
截至目前,在我的日历上,仅在该月所需的文本块(日期)周围放置边框。我有一个 7 列 6 行的网格,即 42 个单元格。一个月最多只有 31 天(单元格),所以我有很多没有边框的空单元格。我怎样才能改变它,以便所有 42 个单元格周围都有边框,使其看起来像日历应该的样子。提前致谢。 :)
<Grid Name="controlGrid" Margin="0,56,0,0">
<Grid.ColumnDefinitions >
<ColumnDefinition Width="86*" />
<ColumnDefinition Width="83*" />
<ColumnDefinition Width="84*" />
<ColumnDefinition Width="84*" />
<ColumnDefinition Width="84*" />
<ColumnDefinition Width="84*" />
<ColumnDefinition Width="84*" />
</Grid.ColumnDefinitions>
<ItemsControl ItemsSource="{Binding schedule}"
Name="Calender"
VerticalAlignment="Stretch"
Grid.ColumnSpan="7"
Margin="0,-8,0,0">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl" >
<Border BorderBrush="CornflowerBlue" BorderThickness="3">
<ItemsPresenter/>
</Border>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid ShowGridLines="False" Name="gridCalender">
<Grid.Background>
<RadialGradientBrush>
<GradientStop Color="#FFC3D6F5" Offset="0" />
<GradientStop Color="#FFEFF5FF" Offset="1" />
</RadialGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderThickness="0.5" BorderBrush="CornflowerBlue">
<TextBlock OpacityMask="Black" Name="txtBlockdays">
<Button Content="{Binding day}"
Width="175"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
VerticalContentAlignment="Top"
HorizontalContentAlignment="Left"
Name="btnCalenderDate"
Click="btnCalenderDate_Click"
Loaded="btnCalenderDate_Loaded"
Height="18"
FontSize="10"
FontWeight="Bold">
</Button>
</TextBlock>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style >
<Setter Property="Grid.Column" Value="{Binding WeekDay}" />
<Setter Property="Grid.Row" Value="{Binding WeekNo}" />
<Setter Property="Control.BorderBrush" Value="Black" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</Grid>
As of now on my calender, a border is onlyplaced around the textblocks(dates) that are needed for that month. I have a grid that has 7 columns and 6 rows so thats 42 cells. A month only has max 31days(cells) so I have a lot of empty cells that dont have a border around it. How can I change this so that all 42 cells has a border around it making it look how a calender should look. Thanks in advance. :)
<Grid Name="controlGrid" Margin="0,56,0,0">
<Grid.ColumnDefinitions >
<ColumnDefinition Width="86*" />
<ColumnDefinition Width="83*" />
<ColumnDefinition Width="84*" />
<ColumnDefinition Width="84*" />
<ColumnDefinition Width="84*" />
<ColumnDefinition Width="84*" />
<ColumnDefinition Width="84*" />
</Grid.ColumnDefinitions>
<ItemsControl ItemsSource="{Binding schedule}"
Name="Calender"
VerticalAlignment="Stretch"
Grid.ColumnSpan="7"
Margin="0,-8,0,0">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl" >
<Border BorderBrush="CornflowerBlue" BorderThickness="3">
<ItemsPresenter/>
</Border>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid ShowGridLines="False" Name="gridCalender">
<Grid.Background>
<RadialGradientBrush>
<GradientStop Color="#FFC3D6F5" Offset="0" />
<GradientStop Color="#FFEFF5FF" Offset="1" />
</RadialGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderThickness="0.5" BorderBrush="CornflowerBlue">
<TextBlock OpacityMask="Black" Name="txtBlockdays">
<Button Content="{Binding day}"
Width="175"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
VerticalContentAlignment="Top"
HorizontalContentAlignment="Left"
Name="btnCalenderDate"
Click="btnCalenderDate_Click"
Loaded="btnCalenderDate_Loaded"
Height="18"
FontSize="10"
FontWeight="Bold">
</Button>
</TextBlock>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style >
<Setter Property="Grid.Column" Value="{Binding WeekDay}" />
<Setter Property="Grid.Row" Value="{Binding WeekNo}" />
<Setter Property="Control.BorderBrush" Value="Black" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用了此处 之前扩展了
Grid
控件以包含允许您指定 GridLine 可见性、粗细和颜色的属性。以防链接失效,代码如下:
I've used the code found here before which extends the
Grid
control to include properties that allow you to specify GridLine visibility, thickness, and colorIn case that link goes dead, here's the code:
只需添加额外的虚拟项目来填充其他单元格......
Just add extra dummy items to fill the other cells...