我正在尝试在按钮标签中传递许多绑定,但我在其标签中收到空结果。 这是代码:
<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
}
但是在我的代码中,Tag 属性返回空我在做什么蛙子吗?我的代码基于这篇文章
您引用的示例仅适用于string
类型的属性,例如 TextBlock.Text
.
对于其他类型(Tag
是object
(,您将不得不使用转换器(此答案使用它(或其他方法。
一种可能性是使用有效的;)代理输出
<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" />