I have a Listbox in a Viewbox.
<ViewBox>
...
<ListBox
x:Name="ListBoxEmp"
Width="620"
Margin="20,0,0,0"
Padding="0,0,0,0"
DockPanel.Dock="Left"
ItemsSource="{Binding Emp}"
ScrollViewer.VerticalScrollBarVisibility="Visible"
SelectedItem="{Binding SelectedEmp, Mode=TwoWay}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate DataType="viewModels:EmpViewModel">
<DockPanel>
<StackPanel>
<TextBlock>
<Run Text="{Binding Lastname}" />
<Run Text="{Binding Firstname}" />
</TextBlock>
<TextBlock>
<Run Text="{Binding Email}" />
</TextBlock>
<TextBlock Text="{Binding Tele}" />
</StackPanel>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
...
</ViewBox>
Whenever I add a new object to the list, the content of the entire window becomes smaller because of the Viewbox I guess. Is there a way to stop the reduction and add a scrollbar to the list box.
I need the Viewbox to proportionally resize the content of the window if the size changes of the window. This is why I am using it.
Thank you
question from:
https://stackoverflow.com/questions/66048024/listbox-in-a-viewbox-listboxverticalscrollbar-doesn%c2%b4t-work 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…