MVVM 模式下 ScrollViewer 用户控件的 LineUp 等方法的调用
我有一个 WPF 3.5 MVVVM 应用程序,它在 ScrollViewer 中有一个 TextBlock。我希望每当文本块中有换行符时都能够调用控件的 LineUp/LineDown 方法。
我如何在不违反任何 MVVM 原则的情况下实现这一点?
提前致谢,
萨蒂亚
<Border BorderThickness="1" BorderBrush="Gray" CornerRadius="1" Margin="2" Grid.Row="0" Grid.Column="3" Grid.RowSpan="2">
<ScrollViewer Name="Scroll" VerticalScrollBarVisibility="Auto" MinWidth="120" Height="80"
CanContentScroll="True"
>
<TextBlock TextWrapping="WrapWithOverflow" Padding="5" FontSize="10" Text="{Binding Path=GetScrollLogMessage}" DockPanel.Dock="Left" />
</ScrollViewer>
</Border>
I have a WPF 3.5 MVVVM application which has a TextBlock in a ScrollViewer. I want to be able to call the LineUp/LineDown method of the control whenever there is a newline in the text block.
How do I implment this without violating any MVVM principles?
Thanks in advance,
Satya
<Border BorderThickness="1" BorderBrush="Gray" CornerRadius="1" Margin="2" Grid.Row="0" Grid.Column="3" Grid.RowSpan="2">
<ScrollViewer Name="Scroll" VerticalScrollBarVisibility="Auto" MinWidth="120" Height="80"
CanContentScroll="True"
>
<TextBlock TextWrapping="WrapWithOverflow" Padding="5" FontSize="10" Text="{Binding Path=GetScrollLogMessage}" DockPanel.Dock="Left" />
</ScrollViewer>
</Border>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在视图模型中引发事件,并在视图的代码隐藏中处理该事件。
Raise an event in your view model, and handle the event in the view's code-behind.
当 textblock.textChanged 事件触发时,您可以执行 ScrollViewer.scrollToBottom()。
You can execute ScrollViewer.scrollToBottom() when textblock.textChanged event fires.