簡體   English   中英

如何在XAML中將FormatString作為ConverterParameter傳遞

[英]How to pass a FormatString as ConverterParameter in XAML

我與轉換器綁定。 我想將“#,. 0M”格式字符串作為轉換器參數傳遞。

此xaml無效:

<local:SalesPerformanceControl FirstSalesVolume="{Binding Path=TodaySalesVolume, Converter={StaticResource ResourceKey=decimalToFormatedStringConverter}, ConverterParameter=#,,.0M}"/>

錯誤

找不到類型“”。

如何正確傳遞此字符串?

在傳遞的字符串上使用單引號:

       <local:SalesPerformanceControl FirstSalesVolume="{Binding Path=TodaySalesVolume, Converter={StaticResource ResourceKey=decimalToFormatedStringConverter}, ConverterParameter='#,,.0M'}"/>

或使用復雜的語法進行如下綁定:

    <local:SalesPerformanceControl>
        <local:SalesPerformanceControl.FirstSalesVolume>
            <Binding Path="TodaySalesVolume" Converter="{StaticResource decimalToFormatedStringConverter}" ConverterParameter="#,,.0M" />
        </local:SalesPerformanceControl.FirstSalesVolume>
    </local:SalesPerformanceControl>

一種方法是在資源中聲明字符串並將其傳遞給轉換器。

<UserControl.Resources>

 <sys:String x:Name="strParam">#,,.0M</sys:String>

    </UserControl.Resources>

像波紋管一樣添加

<local:SalesPerformanceControl FirstSalesVolume="{Binding Path=TodaySalesVolume, Converter={StaticResource ResourceKey=decimalToFormatedStringConverter},   ConverterParameter={StaticResource strParam}}"/>

可以幫助你

嘗試將字符串另存為資源。

首先添加以下xmlns聲明

xmlns:sys="clr-namespace:System;assembly=mscorlib"

然后將字符串保存在資源中

<sys:String x:Key="format">#,,.0M</sys:String>

並如下使用

<local:SalesPerformanceControl FirstSalesVolume="{Binding Path=TodaySalesVolume, Converter={StaticResource ResourceKey=decimalToFormatedStringConverter}, ConverterParameter={StaticResource ResourceKey=format}}"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM