VM内的Setfocus无法正常工作

时间:2016-10-12 22:11:24

标签: c# wpf mvvm

我在我的WPF应用程序中使用了以下代码。我正在尝试将重点放在按钮单击上的文本框中...即。在调用Check()方法...

代码:

MainWindowResources.xaml

 <Style TargetType="TextBox" x:Key="MyFiedlStyle">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=FocusOnMyField}" Value="true">
                <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=myField}"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

MainWindow.xaml

<TextBox HorizontalAlignment="Left" Margin="1,1,0,0" Width="180" Text="{Binding MyAttributes.MyFieldValue}" TabIndex="4" Grid.Row="3" VerticalAlignment="Top" Grid.Column="5" 
                     Name="myField" Style="{DynamicResource MyFieldStyle}"/>

MainWindowViewModel

 private bool FocusOnMyField
        {
            get { return m_FocusOnMyField; }
            set
            {
                m_FocusOnMyField = value;
                OnPropertyChanged("FocusOnMyField");
            }
        }




private void Check()
{
    this.FocusOnSecDescription = true;

}

感谢。

0 个答案:

没有答案