是否可以从xaml更改状态?例如,当第一个按钮发射时 assigh" State"一些值字符串或bool。需要写什么。目标名称应该是什么?
namespace WpfApplication114
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new Data();
}
}
public class Data
{
private string state;
public string State
{
get { return this.state; }
set { this.state = value; }
}
}
代码:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
}
答案 0 :(得分:0)
嗨如果我没有误解你的问题你就可以这样做
TriggerAction类
public class TriggerActionClick : TriggerAction<Button>
{
public string Value { get; set; }
public string TargetName { get; set; }
protected override void Invoke(object parameter)
{
if (AssociatedObject.DataContext != null && !string.IsNullOrEmpty(TargetName))
{
var type=AssociatedObject.DataContext.GetType();
var prop = type.GetProperty(TargetName);
if (prop != null)
prop.SetValue(AssociatedObject.DataContext,Value);
}
}
}
此处单击Button时,xaml中设置的值将设置为DataContext对象的TargetName中指定的Property。