gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:48:03 25 4
gpt4 key购买 nike

我是 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/

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