【发布时间】:2016-05-10 14:08:12
【问题描述】:
我在 c# wpf 中创建了一个UserControl。我想获取TextBox(txtCode)属性框的所有属性
<UserControl x:Class="WpfApplication2.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" Height="315.358" Width="758">
<Grid >
<TextBox x:Name="txtCode" HorizontalAlignment="Left" Height="97" Margin="134,62,0,0" TextWrapping="Wrap" Text="00001" VerticalAlignment="Top" Width="588" FontSize="30"/>
<Label Content="Code" HorizontalAlignment="Left" Margin="27,72,0,0" VerticalAlignment="Top" Width="138" Height="97" FontSize="30"/>
<Button Content="Submit" HorizontalAlignment="Left" Margin="290,186,0,0" VerticalAlignment="Top" Width="247" Height="48" FontSize="30"/>
</Grid>
</UserControl>
在 Windows 窗体中类似于下图
c#代码
public TextBox txtCodeProperties
{
get { return txtCode; }
set { txtCode = value; }
}
【问题讨论】:
-
如果您想查看“控件属性”,只需在焦点控件上按
F4或Alt+Enter。