I have a ListBox with the ItemsPanelTemplate of the canvas. I know that ScrollViewer will not work with Canvas if it is not given height and width. I DO NOT want the canvas to have height and width, because it will not always be permanent. Is there any other job or tricks that someone got to work in this situation. I know that I cannot be the only one with this problem. Thanks in advance, this is my code.
Another problem is that I cannot put the ScrollViewer inside the ItemsPanelTemplate, because it can only contain one item inside.
It also prevents me from placing the canvas inside the grid to get positioning.
XAML:
<ScrollViewer x:Name="scrollViewer"
VerticalScrollBarVisibility="Hidden"
HorizontalScrollBarVisibility="Hidden">
<ListBox x:Name="objCoreViewer"
ItemsSource="{Binding ItemsSource}"
Background="LightGray"
SelectionChanged="objCoreViewer_SelectionChanged"
ItemTemplateSelector="{DynamicResource CoreViewerDataTemplateSelector}"
ItemContainerStyleSelector="{DynamicResource ItemContainerStyleSelector}"
PreviewMouseWheel="objCoreViewer_PreviewMouseWheel">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Canvas x:Name="objCoreViewerCanvas"
Background="Transparent">
<Canvas.LayoutTransform>
<ScaleTransform ScaleX="{Binding Path=Value, ElementName=ZoomSlider}"
ScaleY="{Binding Path=Value, ElementName=ZoomSlider}" />
</Canvas.LayoutTransform>
</Canvas>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</ScrollViewer>
source
share