以编程方式如何在 MultiBinding StringFormat 中提供连续的任意数量的空白字符?

Programmaticaly How to provide consecutive arbitary number of whitespace characters within MultiBinding StringFromat?

请检查以下代码片段:

<TextBox x:Name="TxtBox_CommandInfo"  Style="{DynamicResource MetroTextBox}" IsReadOnly="True" Controls:TextBoxHelper.Watermark="This is a textbox" HorizontalAlignment="Left" Margin="0,236,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="154" Width="780" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
        <TextBox.Text>
            <MultiBinding StringFormat="{}{0}      {1}        {2} {3}&#x20;{4} {5}    {6}          {7}          {8}        {9}        {10}&#x0a;{11}">
                <Binding  Path="No" />
                <Binding  Path="SelectedType" />
                <Binding  Path="IgnoreSignature"/>
                <Binding  Path="IgnoreRelString"/>
                <Binding  Path="DirectDL"/>
                <Binding  Path="LegacySC" />
                <Binding  Path="SelectedDVName"/>
                <Binding  Path="SelectedHCName"/>
                <Binding  Path="SelectedSCName"/>
                <Binding  Path="SCRelease"/>
                <Binding  Path="DALName"/>
                <Binding  Path="PreviousLogs"/>
            </MultiBinding>
        </TextBox.Text>
    </TextBox>

在这里,每当我想格式化绑定参数之间的 space 时,我都必须对连续的白色-space 字符的数量进行硬编码。

我的假设是:

<MultiBinding StringFormat="{}{0}[&#x20;,4]{1}[&#x20;,8]{2}{3}{4}[&#x20;,6]{5}{6}[&#x20;,10]{7}{8}{9}{10}&#x0a;{11}"

意味着而不是像这样输入所需的白色 spaces:

<MultiBinding StringFormat="{}{0} {1} {2}" />

Alternative/Programmatical/Convenient 但假设机制(提供我们想要的白色 space 的数量)如下:

<MultiBinding StringFormat="{}{0}[Character/s,Number of Repetition]{1}[Character/s,Number of Repetition]{2}" /> <!-- Assumed code like --> <MultiBinding StringFormat="{}{0}[&#x20,8]{1}[&#x20,10]{2}" />

谢谢!

您可以添加一个白色的space参数并填充它:

<MultiBinding StringFormat="{}{0}{12,5}{1}{12,5}{2}{12,1}{3}{12,1}{4}{12,1}{5}{12,4}{6}{12,8}{7}{12,8}{8}{12,8}{9}{12,4}{10}&#x0a;{11}">
    <Binding Path="No" />
    <Binding Path="SelectedType" />
    <Binding Path="IgnoreSignature"/>
    <Binding Path="IgnoreRelString"/>
    <Binding Path="DirectDL"/>
    <Binding Path="LegacySC" />
    <Binding Path="SelectedDVName"/>
    <Binding Path="SelectedHCName"/>
    <Binding Path="SelectedSCName"/>
    <Binding Path="SCRelease"/>
    <Binding Path="DALName"/>
    <Binding Path="PreviousLogs"/>
    <Binding Path="SomeBindingPathThatDoesNotExist" FallbackValue=" "/>
</MultiBinding>

{12} 将是您的值(回退值是 space),您可以用 {12,x}

填充它

更好的解决方案是填充每个绑定。这为您提供了每个绑定的固定大小(不会添加恒定数量的白色 spaces),但这通常是您想要的:

<MultiBinding StringFormat="{}{0,10}{1,10}{2,8}(etc.)">
    <Binding Path="No" />
    <Binding Path="SelectedType" />
    <Binding Path="IgnoreSignature"/>
    <Binding Path="IgnoreRelString"/>
    <Binding Path="DirectDL"/>
    <Binding Path="LegacySC" />
    <Binding Path="SelectedDVName"/>
    <Binding Path="SelectedHCName"/>
    <Binding Path="SelectedSCName"/>
    <Binding Path="SCRelease"/>
    <Binding Path="DALName"/>
    <Binding Path="PreviousLogs"/>
</MultiBinding>