簡體   English   中英

WPF - 從 XAML 中的 StringFormat 綁定屬性訪問屬性值

[英]WPF - access a property value from the StringFormat binding property in XAML

是否可以從 XAML 中的 StringFormat 綁定屬性訪問屬性值? 我的意思是,這是我的 XAML:

<TextBox Name="costBlock" Grid.Row="4" Grid.Column="1" Margin="4" IsEnabled="False"
    Text="{Binding DataContext.CalculatedCost, Mode=OneWay, StringFormat={}{0} €}"></TextBox>

我需要將 StringFormat 綁定中的“€”符號替換為所選貨幣的符號,這是靜態類中的一個屬性:Settings.SelectedCurrencySymbol。

我該怎么做?

感謝 Clemens 的推薦,我找到了這個解決方案:

<TextBlock Name="costBlock" Grid.Row="4" Grid.Column="1" Margin="4" 
    IsEnabled="False">
        <TextBlock.Text>
            <MultiBinding StringFormat="{}{0} {1}">
                <Binding Path="DataContext.CalculatedCost" />
                <Binding Path="(shared:Settings.SelectedCurrencySymbol)" />
            </MultiBinding>
        </TextBlock.Text>
    </TextBlock>

暫無
暫無

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

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