如何在子元素中绑定 属性?
How to bind a property inside a child element?
我想使用两个 属性 值来定义元素是否启用。
到目前为止,以下行决定启用/禁用一个元素。 IsEnabled
决定于
绑定到 someContext.SomeObject.Count
<ToggleButton Style="{StaticResource CheckButtonStyle}" Margin="1"
IsChecked="{Binding Path=someContext[3], ElementName=MyElementName, IsAsync=True}"
IsEnabled="{Binding Path=someContext.SomeObject.Count, ElementName=MyElementName, Converter={StaticResource MyConverter}, ConverterParameter=3}" />
我将转换器更改为 IMultiValueConverter 并且
我将 XAML 更改为以下内容:
<ToggleButton Style="{StaticResource CheckButtonStyle}" Margin="1"
IsChecked="{Binding Path=someContext[3],
ElementName=MyElementName, IsAsync=True}">
<ToggleButton.IsEnabled>
<MultiBinding Converter="{StaticResource MyMultiValueConverter}" ConverterParameter="3">
<Binding Path="{someContext.SomeObject.Count}"/>
<Binding Path="{IsConditionFullfilled}/>
</MultiBinding>
</ToggleButton.IsEnabled>
</ToggleButton>
然而,在第一个版本中,大括号内的绑定被识别,
但在第二个版本中我得到:
"The type 'someContext' was not found. Verify that you are not missing
an assembly reference and that all referenced assemblies have been build."
我认为 <ToggleButton.IsEnabled></ToggleButton.IsEnabled>
无法访问与其父级相同的命名空间 <ToggleButton />
我该如何解决?
去掉名字两边的大括号,否则会被解释为markup extensions.
When used to provide an attribute value, the syntax that distinguishes a markup extension sequence to a XAML processor is the presence of the opening and closing curly braces ({ and }). The type of markup extension is then identified by the string token immediately following the opening curly brace.
此外,如果仍然需要,请从原始绑定中添加 ElementName
。
<MultiBinding Converter="{StaticResource MyMultiValueConverter}" ConverterParameter="3">
<Binding Path="someContext.SomeObject.Count" ElementName="MyElementName"/>
<Binding Path="IsConditionFullfilled"/>
</MultiBinding>
我想使用两个 属性 值来定义元素是否启用。
到目前为止,以下行决定启用/禁用一个元素。 IsEnabled
决定于
绑定到 someContext.SomeObject.Count
<ToggleButton Style="{StaticResource CheckButtonStyle}" Margin="1"
IsChecked="{Binding Path=someContext[3], ElementName=MyElementName, IsAsync=True}"
IsEnabled="{Binding Path=someContext.SomeObject.Count, ElementName=MyElementName, Converter={StaticResource MyConverter}, ConverterParameter=3}" />
我将转换器更改为 IMultiValueConverter 并且 我将 XAML 更改为以下内容:
<ToggleButton Style="{StaticResource CheckButtonStyle}" Margin="1"
IsChecked="{Binding Path=someContext[3],
ElementName=MyElementName, IsAsync=True}">
<ToggleButton.IsEnabled>
<MultiBinding Converter="{StaticResource MyMultiValueConverter}" ConverterParameter="3">
<Binding Path="{someContext.SomeObject.Count}"/>
<Binding Path="{IsConditionFullfilled}/>
</MultiBinding>
</ToggleButton.IsEnabled>
</ToggleButton>
然而,在第一个版本中,大括号内的绑定被识别, 但在第二个版本中我得到:
"The type 'someContext' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been build."
我认为 <ToggleButton.IsEnabled></ToggleButton.IsEnabled>
无法访问与其父级相同的命名空间 <ToggleButton />
我该如何解决?
去掉名字两边的大括号,否则会被解释为markup extensions.
When used to provide an attribute value, the syntax that distinguishes a markup extension sequence to a XAML processor is the presence of the opening and closing curly braces ({ and }). The type of markup extension is then identified by the string token immediately following the opening curly brace.
此外,如果仍然需要,请从原始绑定中添加 ElementName
。
<MultiBinding Converter="{StaticResource MyMultiValueConverter}" ConverterParameter="3">
<Binding Path="someContext.SomeObject.Count" ElementName="MyElementName"/>
<Binding Path="IsConditionFullfilled"/>
</MultiBinding>