WPF宽度与星号绑定到属性

时间:2019-03-08 14:32:13

标签: c# wpf data-binding width

例如,是否可以将属性的宽度绑定到对象乘以星号的值,

(Width =“ {Binding SizeInt *}”)xaml?

在后面的代码中,您可以执行以下操作:

const emitter = {
  handlers: {},

  on(eventName, handler) {
    if (!this.handlers[eventName])
      this.handlers[eventName] = [];

    this.handlers[eventName].push(handler);
  },

  emit(eventName, data) {
    for (const handler of this.handlers[eventName])
      handler(data);
  }
};

emitter.on('foo', data => console.log(data.text));

emitter.emit('foo', { text: 'Foo event triggered' });

我希望能够在xaml中具有相同的效果...

rect.Width = new GridLength(item.SizeInt, GridUnitType.Star);

有没有一种方法可以使用xaml?

1 个答案:

答案 0 :(得分:0)

尝试绑定到GridLength来源属性:

public GridLength SizeInt => new GridLength(1, GridUnitType.Star);

您可以将1替换为所需的任何值,包括另一个字段的值。