Class 和文本的多重绑定 StringFormat
Multibinding StringFormat for Class and Text
我有一个看起来像这样的 StackPanel:
<StackPanel Orientation="Horizontal">
<TextBlock Text="{helpers:Localization PIV_HdrTblPtnId}" />
<TextBlock Text="{Binding Path=(utils:NavigationVariables.Id)}" />
</StackPanel>
我正在尝试将其转换为单个 TextBlock,如下所示:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="{helpers:Localization PIV_HdrTblPtnId}"/>
<Binding Path="(utils:NavigationVariables.Id)"
UpdateSourceTrigger="PropertyChanged" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
但我收到以下错误:
'A 'Localization' cannot be set on the 'Path' property of
type 'Binding'.
有什么办法可以解决这个问题吗?提前致谢!
编辑:
本地化 class:
public class LocalizationExtension : Binding
{
#region Constructors
public LocalizationExtension(string name) : base("[" + name + "]")
{
Mode = BindingMode.OneWay;
Source = CultureManager.Instance;
}
#endregion
}
具有两个运行的 TextBlock 应该可以工作:
<TextBlock>
<Run Text="{helpers:Localization PIV_HdrTblPtnId}"/>
<Run Text="{Binding Path=(utils:NavigationVariables.Id), Mode=OneWay}" />
</TextBlock>
我有一个看起来像这样的 StackPanel:
<StackPanel Orientation="Horizontal">
<TextBlock Text="{helpers:Localization PIV_HdrTblPtnId}" />
<TextBlock Text="{Binding Path=(utils:NavigationVariables.Id)}" />
</StackPanel>
我正在尝试将其转换为单个 TextBlock,如下所示:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="{helpers:Localization PIV_HdrTblPtnId}"/>
<Binding Path="(utils:NavigationVariables.Id)"
UpdateSourceTrigger="PropertyChanged" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
但我收到以下错误:
'A 'Localization' cannot be set on the 'Path' property of type 'Binding'.
有什么办法可以解决这个问题吗?提前致谢!
编辑: 本地化 class:
public class LocalizationExtension : Binding
{
#region Constructors
public LocalizationExtension(string name) : base("[" + name + "]")
{
Mode = BindingMode.OneWay;
Source = CultureManager.Instance;
}
#endregion
}
具有两个运行的 TextBlock 应该可以工作:
<TextBlock>
<Run Text="{helpers:Localization PIV_HdrTblPtnId}"/>
<Run Text="{Binding Path=(utils:NavigationVariables.Id), Mode=OneWay}" />
</TextBlock>