简体   繁体   English

WPF - 从 XAML 中的 StringFormat 绑定属性访问属性值

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

Is it possible to access a property value from the StringFormat binding property in XAML?是否可以从 XAML 中的 StringFormat 绑定属性访问属性值? I mean, this is my XAML:我的意思是,这是我的 XAML:

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

I need to replace the "€" symbol in the StringFormat bindingby the symbol of the selected currency, which is a property in a static class: Settings.SelectedCurrencySymbol.我需要将 StringFormat 绑定中的“€”符号替换为所选货币的符号,这是静态类中的一个属性:Settings.SelectedCurrencySymbol。

How can I do it?我该怎么做?

Thanks to Clemens reccommendation I found this solution:感谢 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