【问题标题】:Adjusting the User control to Stackpanel's size将用户控件调整为 Stackpanel 的大小
【发布时间】:2017-05-12 08:53:13
【问题描述】:

我是 WPF 新手,遇到了一个小问题。我有一个包含 Stackpanel 的 UserControl。堆栈面板内部有多个richtxtboxes,它将根据运行时的条件可见或折叠。问题是,用户控件的大小保持不变(我希望它是运行时堆栈面板的大小)。我已经使用一些值将高度和宽度属性设置为用户控件。我已经搜索过它并得到了删除高度和宽度属性的建议。但这会使整个 wpf 面板崩溃。有人可以帮忙吗?

【问题讨论】:

    标签: c# wpf


    【解决方案1】:

    设置 const 大小并不好 - 仅在需要时。无论如何,这是您的解决方案

    <UserControl x:Class="WpfApp1.UserControl1"
                 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" 
                 xmlns:local="clr-namespace:WpfApp1"
                 mc:Ignorable="d" 
                 d:DesignHeight="300" d:DesignWidth="300"
                 Width="{Binding ElementName=MyStackPanel, Path=ActualWidth}"
                 Height="{Binding ElementName=MyStackPanel, Path=ActualHeight}">
    
        <Grid>
    
            <StackPanel Width="350" 
                        Height="350" 
                        x:Name="MyStackPanel" 
                        Background="Blue" />
    
        </Grid>
    
    </UserControl>
    

    【讨论】:

    • 非常感谢。完美:)祝你有美好的一天!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多