gpt4 book ai didi

c# - ReactiveUI - View 未正确呈现(或完整呈现)

转载 作者:太空宇宙 更新时间:2023-11-03 19:05:05 25 4
gpt4 key购买 nike

我正在开始一个新项目,使用 ReactiveUIMahApps.Metro。我遇到的第一个障碍是 View 没有完整显示的问题。我有一个 Window,在那个 Window 中我有一个来自 RxUI 库的 ViewModelViewHost。它是嵌套 View 模型的简单容器。 ActiveItem 绑定(bind)已正确绑定(bind)到用户控件的 View 模型,并且用户控件中的 Button 在屏幕上可见。

我希望看到的是一个深灰色背景的窗口,中间有一个按钮。我看到的是带有默认背景的 Window 和中间的 Button。这个不对。如果我删除按钮,我在 Window 上什么也看不到,只有默认背景。

ViewModelViewHost 似乎只显示了 UserControl 的实际内容,而忽略了不被视为真正控件的内容,例如网格等。

有没有人遇到过这种行为?

<mah:MetroWindow x:Class="...MainWindow"
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:rx="clr-namespace:ReactiveUI;assembly=ReactiveUI"
WindowStartupLocation="CenterScreen"
ShowTitleBar="False"
ShowCloseButton="False"
ShowMaxRestoreButton="False"
ShowMinButton="False"
Height="768"
Width="1024">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<rx:ViewModelViewHost ViewModel="{Binding ActiveItem}" />
</Grid>
</mah:MetroWindow>


<UserControl x:Class="...NestedView"
Name="TheUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
TextOptions.TextHintingMode="Auto"
TextOptions.TextRenderingMode="Auto"
d:DesignHeight="768" d:DesignWidth="1024">

<Grid Background="DarkGray">
<Button Width="200" Height="100" />
</Grid>
</UserControl>

最佳答案

这不会是 ReactiveUI 问题,只是一个简单的 WPF 问题。

ViewModelViewHost 在您的窗口中居中。当您的 UserControl 设置了 DesignHeightDesignWidth 时,当它在运行时呈现时,它会自动调整自身大小以适应其内容的高度和宽度 - 按钮

VerticalContentAlignment="Stretch"Horizo​​ntalContentAlignment="Stretch" 添加到您的 ViewModelViewHost 声明并删除其他两个 Alignment 属性(它们默认为Stretch),它应该将其内容拉伸(stretch)到 Window 的大小,同时将任何具有固定大小的项目居中。

关于c# - ReactiveUI - View 未正确呈现(或完整呈现),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29395102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com