我有这样的数据网格模板:
<ControlTemplate TargetType="{x:Type DataGrid}" x:Key="zoomableControl">
<ScrollViewer x:Name="scrollViewer" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Grid
<ContentPresenter>
</ContentPresenter>
<Slider Name="zoomSlider" Minimum="1" Maximum="100" Visibility="Hidden"/>
<Grid.LayoutTransform>
<ScaleTransform ScaleX="{Binding Path=Value,ElementName=zoomSlider}" ScaleY="{Binding Path=Value,ElementName=zoomSlider}"/>
</Grid.LayoutTransform>
</Grid>
</ScrollViewer>
</ControlTemplate>
并像这样使用它:
<DataGrid Template="{StaticResource zoomableControl}" ...>
我想在模板内的ScrollViewer中显示datagrid,但它没有显示任何内容。有什么问题?
答案 0 :(得分:0)
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ContentPresenter >
</ContentPresenter>
<Slider Name="zoomSlider" Minimum="1" Maximum="100" Visibility="Hidden" Grid.Row="1"/>
<Grid.LayoutTransform>
<ScaleTransform ScaleX="{Binding Path=Value,ElementName=zoomSlider}" ScaleY="{Binding Path=Value,ElementName=zoomSlider}"/>
</Grid.LayoutTransform>
</Grid>
您的ContentPresenter和Slider位于Grid的同一行,因此ContentPresenter不会显示为Slider覆盖它。我希望这会有所帮助。