c# - 如何在运行时在 wpf 中调整用户控件的大小

标签 c# visual-studio-2008 user-controls wpf-controls

我是 wpf 开发的新手。在我的 wpf 应用程序中,我使用了用户控件。我需要的是在运行时如何调整用户控件的大小

请帮助我找到解决方案,如果我的方法有误,请指导我获得解决方案,

我的 XAML 代码是

<UserControl x:Class="test.pad"
             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" 
             d:DesignHeight="300" d:DesignWidth="300" Focusable="True" OverridesDefaultStyle="False">

    <Grid Width="102" Height="123" Name="Grid1" MouseMove="Grid1_MouseMove" MouseUp="Grid1_MouseUp" MouseDown="Grid1_MouseDown">
        <Grid.RenderTransform>
            <TranslateTransform x:Name="tt"/>
        </Grid.RenderTransform>

        <Border BorderBrush="Silver" BorderThickness="2">

            <Canvas Height="120" HorizontalAlignment="Left" Margin="0,1,0,0" Name="canvas1" VerticalAlignment="Top" Width="100" Grid.ColumnSpan="2">
                <RichTextBox Height="98" HorizontalAlignment="Left" Margin="0,24,0,0" Name="richTextBox1" VerticalAlignment="Top" Width="100" BorderThickness="2" Grid.ColumnSpan="2" Background="#FFFF96D8" Canvas.Top="-3" Canvas.Left="-1" />
                <Button BorderBrush="#FFFF96D8" Canvas.Left="46" Canvas.Top="-2" Height="23" Name="close" Width="27">

                </Button>
                <Button Height="23" Name="minimise" Width="27" BorderBrush="#FFFF96D8" Click="button1_Click" Canvas.Left="72" Canvas.Top="-2" ClipToBounds="False" IsEnabled="True" IsHitTestVisible="True" OverridesDefaultStyle="False" ForceCursor="False" Foreground="Black" MouseMove="button1_MouseEnter" MouseLeave="button1_MouseLeave">

            </Canvas>

        </Border>

    </Grid>
</UserControl>

谢谢 灰

最佳答案

移除 UserControlHeightWidth 以及 Grid
在您调用它的地方为 UserControl 设置 MarginSize 属性。

关于c# - 如何在运行时在 wpf 中调整用户控件的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6514671/

相关文章:

Silverlight:将相同的用户控件添加到多个 Canvas

c# - ListView中的自定义ListViewItem

c# - 在 Xamarin ios 中显示不同样式(列表、网格、 block )的项目?

c# - 如何在 Blazor 中的输入更改上绑定(bind)和运行异步方法

visual-studio-2008 - 使用 Visual Studio 2008 编辑 RDL 文件

c++ - 使用 boost 1.4.2 时命名空间前缺少 ';'

wpf - 如何在 WPF 中为用户控件创建用户定义(新)事件?一个小示例

c# - 在 C# .NET 中按资源组列出 azure 工作区

c# - 在 C# 中使用 C++ 方法

c# - 如何通过命令提示符调用 MSBuild?