Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

c# - Listbox in a Viewbox ListboxVerticalScrollbar doesn´t work

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this

<ViewBox>
<ContentControl>
    <ListBox.........>
         .............
    </ListBox>
</ContentControl>
</ViewBox>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...