我已经搜索了全部,即使每个人似乎都有这个问题,我也找不到解决我的特定问题的修复程序。
这是问题。我想进行自定义日历控件。为了做到这一点
,但由于某种原因,ScrollViewer滚动栏似乎是禁用的,并且似乎并没有意识到它充满了数据。
这是我的代码
<Grid>
<ScrollViewer>
<ItemsControl ItemsSource="{Binding CalendarDates}" Height="75">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="local:Calender">
<TextBlock Name="CalendarDate" FontSize="12" Text="{Binding}" TextAlignment="Right" VerticalAlignment="Top" Height="Auto"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1" Columns="7"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
</Grid>
,这是我的mainwindow.xaml,我在这里初始化它
<Grid>
<!--Row Definitins -->
<Grid.RowDefinitions>
<RowDefinition Height = "Auto"/>
<RowDefinition Height = "*"/>
<RowDefinition Height = "Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="25*"/>
<ColumnDefinition Width="10*"/>
</Grid.ColumnDefinitions>
<localControl:Calender Grid.Column="1" Grid.Row="1"/>
</Grid>
代码可以很好地填充滚动浏览器,但是就像我在滚动栏上方所说的那样,即使我硬编码大小,它仍然无法正常工作!
我也已经尝试设置sccrollviewer.verticalscrollbar =可见,以及滚动浏览器的高度,以及在堆栈溢出上的十几个"修复",但在我的情况下,它们都没有用来
我找到了答案... itemscontrol模板本身不允许滚动浏览器。
我在第38页的本杂志中找到了答案。
https://dncmagazine.blob.core.windows.net/edition20/dncmag-issue20.pdf
我们需要修改ItemScontrol模板如下:
<ItemsControl.Template>
<ControlTemplate TargetType= "ItemsControl">
<ScrollViewer>
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>