我可以避免将 TreeViewItem 的内容放在 WPF 窗口的左上角吗?

我有一个 WPF 窗口,它在 TreeView 中有一些 ListView。每当 TreeViewItem 的内容变得太高和/或太宽时,只要我单击 TreeViewItem“内部”的空闲点,内容就会被放置在窗口的左上角(见图)。是否有任何可能性/财产可以避免这种情况?我想把滚动到哪里的选择留给用户,并且不想在他不小心点击某个地方时打断他的阅读。


简化示例:


    Title="MainWindow" Height="150" Width="400">


<TreeView>

    <TreeViewItem Header="Some Headline" IsExpanded="True">

        <TreeViewItem Header="Some Text" IsExpanded="True">

            <TextBlock Width="400" Height="150" Background="PaleGreen"> Some Text in a Block</TextBlock>

        </TreeViewItem>

    </TreeViewItem> 

</TreeView>


UYOU
浏览 72回答 1
1回答

汪汪一只猫

这个怎么样?<TreeView>&nbsp; &nbsp; &nbsp; &nbsp; <TreeView.Resources>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Style TargetType="TreeViewItem">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <EventSetter Event="RequestBringIntoView" Handler="TreeViewItem_RequestBringIntoView"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </Style>&nbsp; &nbsp; &nbsp; &nbsp; </TreeView.Resources>&nbsp; &nbsp; &nbsp; &nbsp; <TreeViewItem Header="Some Headline" IsExpanded="True">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TreeViewItem Header="Some Text" IsExpanded="True">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextBlock Width="400" Height="150" Background="PaleGreen"> Some Text in a Block</TextBlock>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </TreeViewItem>&nbsp; &nbsp; &nbsp; &nbsp; </TreeViewItem>&nbsp; &nbsp; </TreeView>后面的代码:private void TreeViewItem_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.Handled = true;&nbsp; &nbsp; &nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP