标签中的 MultiBinding 返回 null

MultiBinding in a Tag is returning null

我试图在一个按钮标签中传递许多绑定,但我在其标签中收到了一个空结果。这是代码:

<Button Click="ViewDanfSingle"  VerticalContentAlignment="Top" Margin="0 -4 0 0"  Grid.Column="1"  Style="{StaticResource buttonTransparent}">
    <Button.Tag>
        <MultiBinding StringFormat="{}{0} + {1}">
             <Binding Path="XmlSequencia"/>
             <Binding Path="NfesaiChaveAcesso"/>
        </MultiBinding>
    </Button.Tag>
</Button>

这是我收到标签值的代码:

private void ViewDanfSingle(object sender, RoutedEventArgs e)
{
     Button btn =  (Button)sender;
     string mytag =  btn.Tag.ToString();
}

模特是这个

public class NfeSaida
{
    #region Constantes

    public const int TamanhoMaximoChaveAcesso = 44;
    public const int TamanhoMaximoRazaoNome = 60;
    public const int TamanhoMaximoNomeFantasia = 60;

    #endregion



        #region Propriedades

    public int NfesaiSequencia { get; set; }
    public int? EmpSequencia { get; set; }
    public int? EdnfeSequenciaDest { get; set; }
    public int? XmlSequencia { get; set; }
    public int UsuSequenciaInclusao
        #endregion

}

但在我的代码中,标签 属性 返回 null 我在做错事吗?我基于我的代码 on this post

您引用的示例仅适用于 string 类型的属性,例如TextBlock.Text.

对于其他类型(Tag is object) you will have to use a converter (this 答案使用它)或其他方法。


一种可能性是 proxy 使用正在工作的东西输出 ;)

<TextBlock Visibility="Collapsed" x:Name="hiddenText">
    <TextBlock.Text>
        <MultiBinding StringFormat="{}{0} + {1}">
            <Binding Path="XmlSequencia" />
            <Binding Path="NfesaiChaveAcesso" />
        </MultiBinding>
    </TextBlock.Text></TextBlock>
<!-- use collapsed textblock to generate content for button tag -->
<Button Tag="{Binding Text, ElementName=hiddenText}" Click="ViewDanfSingle" />