【问题标题】:how to Set property of user control to its child controls in silverlight.?如何在silverlight中将用户控件的属性设置为其子控件。?
【发布时间】:2011-09-19 07:43:28
【问题描述】:

我创建了一个用户控件。 XAML 代码如下。

<UserControl x:Class="UserControlsLibrary.NumericUpDown1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="70">
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" >
    <TextBox x:Name="InputTextBox" Grid.Row="0" Grid.Column="0" Grid.RowSpan="1"
             />
</StackPanel>

这是我的Usercontrol在MainPage.xaml中的实现XAML代码如下

<UserControl x:Class="UserControlsLibrary.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DependencyPropertyBinding"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<StackPanel Height="350" Width="400" Orientation="Horizontal">
    <userControl:NumericUpDown1 x:Name="myusercontrol" TabIndex="34""/>
    <Button Content="Show" Height="40" Width="150" Click="Button_Click" >         </Button>
</StackPanel>

我想将 MainPage.xaml 中 UserControl 的 TabIndex 属性设置为 UserControl 的 TextBox 的 TabIndex 属性的 TabIndex 属性。

如何设置???

【问题讨论】:

  • 答案: 在 TextBox 的 GotFocus 事件中 我将用户控件 TabIndex 分配给 TextBox tabIndex 并且它可以工作。 InputTextBox 是用户控件内的控件名称。私人无效 InputTextBox_GotFocus(对象发送者,RoutedEventArgs e){ this.InputTextBox.TabIndex = this.TabIndex; }
  • 请不要使用 cmets 来放置答案,当然也不要尝试在 cmets 中包含代码。您可以回答自己的问题,以便其他发现您的问题的人受益。

标签: wpf silverlight


【解决方案1】:

Answer : 在 TextBox 的 GotFocus 事件中,我将用户控件 TabIndex 分配给 TextBox tabIndex 并且它可以工作。 InputTextBox 是用户控件内的控件名称。私人无效 InputTextBox_GotFocus(对象发送者,RoutedEventArgs e){ this.InputTextBox.TabIndex = this.TabIndex; }

【讨论】:

    猜你喜欢
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多