gpt4 book ai didi

silverlight - 向文本框添加依赖属性

转载 作者:行者123 更新时间:2023-12-03 10:49:16 25 4
gpt4 key购买 nike

如何将依赖属性添加到文本框并将依赖属性绑定(bind)到银光中的 bool 属性。我的 bool 属性在我的 View 模型中。

ImageSearchIsFocused 是允许我将焦点设置在文本框上的属性。

<TextBox  Text="{Binding ImgSearch, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">   
<i:Interaction.Behaviors>
<common:FocusBehavior HasInitialFocus="True" IsFocused="{Binding ImageSearchIsFocused, Mode=TwoWay}" ></common:FocusBehavior>
</i:Interaction.Behaviors>
</TextBox>

ImageIsFocused 属性
bool _ImageSearchIsFocused;
public bool ImageSearchIsFocused
{
get { return _ImageSearchIsFocused; }
set
{
_ImageSearchIsFocused = value;
NotifyPropertyChanged("ImageSearchIsFocused");
}
}

最佳答案

如果要添加依赖属性,您将拥有 TextBox 的子类并将依赖属性添加到您的子类。然后你可以把它绑定(bind)到你喜欢的任何东西上:

public class MyTextBox : TextBox
{

public static readonly DependencyProperty MyBooleanValueProperty = DependencyProperty.Register(
"MyBooleanValue", typeof(bool), typeof(MyTextBox),
new PropertyMetadata(new PropertyChangedCallback(MyBooleanValueChanged)));
public bool MyBooleanValue
{
get { return (bool)GetValue(MyBooleanValueProperty); }
set { SetValue(MyBooleanValueProperty, value); }
}

private static void MyBooleanValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var propValue = (bool)e.NewValue;
var control = d as MyTextBox;

// do something useful
}

}

关于silverlight - 向文本框添加依赖属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11465366/

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