简体   繁体   中英

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? I mean, this is my 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.

How can I do it?

Thanks to Clemens reccommendation I found this solution:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM