本文介绍了Usercontrol,在其父Canvas.control的左侧设置10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<Canvas>
<wpfUCAllInOne:UC_TextBox Canvas.Left="100" Canvas.Top="100" Width="80" />
</Canvas>
此用户控件(UC_TextBox)在画布左侧设置为100.
This usercontrol (UC_TextBox) is set 100 to the left of the canvas.
<UserControl x:Class="UC_TextBox"
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="100" d:DesignWidth="300">
</UserControl>
但是如何将此控件120设置为用户控件中的画布。没有父控制或类似的东西。
But how do I set this control 120 to the canvas IN the usercontrol. There is no parent control or something like it.
推荐答案
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Canvas.SetLeft(this, 120);
}
}
UserControl.xaml:
UserControl.xaml:
<UserControl x:Class="WpfApplication14.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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid removed="Aqua">
<Button Content="Button" Height="23" HorizontalAlignment="Left" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
</UserControl>
最诚挚的问候,
Shai
Best Regards,
Shai
这篇关于Usercontrol,在其父Canvas.control的左侧设置10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!