ScrollViewer 已多次设置content
时间: 2024-01-26 16:03:00 浏览: 29
ScrollViewer can be set with content multiple times. This means that the content inside the ScrollViewer can be changed dynamically. For example, if you have a list of items that needs to be displayed inside the ScrollViewer, you can add or remove items from the list and set it as the content of the ScrollViewer again. This will update the content displayed inside the ScrollViewer. Here's an example of how to set the content of a ScrollViewer in WPF:
```xml
<ScrollViewer>
<StackPanel>
<!-- Content goes here -->
</StackPanel>
</ScrollViewer>
```
You can also set the content dynamically in the code behind using the `Content` property of the ScrollViewer. For example:
```csharp
var scrollViewer = new ScrollViewer();
var stackPanel = new StackPanel();
// Add content to stack panel
scrollViewer.Content = stackPanel;
// Later, update the content
stackPanel.Children.Clear();
// Add new content to stack panel
scrollViewer.Content = stackPanel;
```
In this example, we first create a new ScrollViewer and a StackPanel to hold the content. We then set the StackPanel as the content of the ScrollViewer. Later, we clear the children of the StackPanel and add new content to it. Finally, we set the updated StackPanel as the content of the ScrollViewer again. This will update the content displayed inside the ScrollViewer.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![xaml](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)